我一直收到“预期的标识符或”(“错误,但我似乎找不到解决这个问题的方法。我的代码已附上
我读到它可能是由于缺少函数名称/定义引起的。我已经有了,所以我不确定还有什么要检查的,因为我正在使用 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);
}
float half(float bill, float tax, int tip);
的定义后面不应该跟分号。
您在声明时以分号结束函数原型,而不是在定义时。