1
看起来这可能是O'Reilly出版的Head First C,2012,Griffiths and Griffiths中的一个错字。在p。 165,有一个练习:本书错误?功能上的不必要的分号(Head First C example,Griffiths&Griffiths 2012)
“有一个新的计划帮助头等第一餐馆的服务员巴士桌子,代码会自动汇总一张账单,并为每件物品增加销售税,看看你是否能找出需要去的东西在每个空白处“
该错误似乎在第7行,float add_with_tax(float f);
。定义函数时,分号不应该在这里。我对此是否正确?
#include <stdio.h>
float total = 0.0;
short count = 0;
short tax_percent = 6;
float add_with_tax(float f); // we're returning a small cash value, so it'll be a float
{
float tax_rate = 1 + tax_percent/100.0;
total = total + (f * tax_rate);
count = count + 1;
return total;
}
int main(){
float val;
printf("Price of item: ");
while (scanf("%f", &val) == 1){
printf("Total so far: %.2f\n", add_with_tax(val));
printf("Price of item: ");
}
printf("\nFinal total: %.2f\n", total);
printf("Number of items: %hi\n", count);
return(0);
}
是的,你是对的。该semiolon不应该在那里。 –
有些拼写错过了编辑的情况并不罕见。许多非小说类书籍(特别是与计算机相关的教科书)可能有* errata *列表问题。您还应该尝试找到可能修复此类错误的更新版本。 –
已确认错误:http://www.oreilly.com/catalog/errata.csp?isbn=0636920015482 –