CS50 Pset1现金错误“期望的标识符或'('”的含义? [英] CS50 Pset1 Cash error "expected identifier or '('" meaning?

查看:126
本文介绍了CS50 Pset1现金错误“期望的标识符或'('”的含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <cs50.h>
#include <math.h>

int main(void)
{
    {
        float dollars;
        // prompt user for "0.00" value
        do
        {
            dollars = get_float("Change owed: ");
        }
        while(dollars <= 0);
    }
    // print amount of coins used for change
        printf("%f\n", get_change(dollars));

    int get_change(float dollars);

    {
        //calculate which coins will be used
        int cents = round(dollars * 100);
        int coins = 0;
        int denom[] = {25, 10, 5, 1};

        for (int i = 0; i < 4; i++);
        {
            coins += cents / denom[i];
            cents = cents % denom[i];
        }
        return coins;
    }
}

在CS50中执行Pset1,我完全迷失了为什么我的代码无法正常工作。获取语​​法错误

Doing Pset1 in CS50 and I'm completely lost as to why my code isn't working. Getting syntax error


cash.c:6:1:error:预期的标识符或'('

cash.c:6:1: error: expected identifier or '('


推荐答案

您应在此行中删除;

for (int i = 0; i < 4; i++);

此处:

int get_change(float dollars);

get_change 移至文件首位或使用函数声明。

move get_change to first of file or use function declarations.

这篇关于CS50 Pset1现金错误“期望的标识符或'('”的含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆