尝试扫描输入到收入中的值时遇到错误,此代码有什么问题?我认为这与两次使用收入有关,我可以简单地更改变量的名称,这是解决该问题的另一种方法吗?
#include <stdio.h>
float TaxDue(float income){
float tax = 0;
if (income < 0){
printf("\nYou've Enter A Negative Income");
}
else if (income <= 750){
tax = (income * .01);
}
else if (income <= 2250){
tax = 7.50 + ((income - 750) * .02);
}
else if (income <= 3750){
tax = 37.50 + ((income - 2250) * .03);
}
else if (income <= 5250){
tax = 82.50 + ((income - 3750) * .04);
}
else if (income <= 7000){
tax = 142.50 + ((income - 5250) * .05);
}
else if (income > 7000){
tax = 230.00 + ((income - 7000) * .06);
}
else{
printf("\nError");
}
return tax;
}
int main(void){
float income = 0;
printf("Enter Your Taxable Income: ");
scanf("%f", income);
printf("\nYou Owe %f In Taxes", TaxDue(income));
return 0;
}
最佳答案
在main中更改以下语句:
scanf("%f", income);
如
scanf("%f", &income);
关于c - 在C中使用函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26171952/