如何修复 C 中的预期标识符错误?

问题描述 投票:0回答:1

我一直收到“预期的标识符或”(“错误,但我似乎找不到解决这个问题的方法。我的代码已附上Screenshot of code

我读到它可能是由于缺少函数名称/定义引起的。我已经有了,所以我不确定还有什么要检查的,因为我正在使用 CS50 进行自学

代码:

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

float half(float bill, float tax, int tip); //function declaration

int main(void)

    {
        float bill_amount = get_float("Bill before tax and tip: ");
        float tax_percent = get_float("Sale Tax Percent: ");
        int tip_percent = get_int("Tip percent: ");

        printf("You will owe $%.2f each!\n", half(bill_amount, tax_percent, tip_percent)); //function call
    }


float half(float bill, float tax, int tip); //function definition
    {
        float result, plus_tax;
        float bill = bill_amount;
        float tax = tax_amount / 100;
        int tip = tip_percent / 100;
        plus_tax = bill + bill * tax;
        result = plus_tax + plus_tax * tip;
        return(result);
    }
c compiler-errors identifier
1个回答
2
投票

float half(float bill, float tax, int tip);
的定义后面不应该跟分号。 您在声明时以分号结束函数原型,而不是在定义时。

© www.soinside.com 2019 - 2024. All rights reserved.