2017-11-25 7 views
1

O'Reilly가 발행 한 2012 년 Griffiths and Griffiths의 Head First C에서 오타가있는 것 같습니다. p. 165, 운동이 있습니다 :북 오류? 기능상 불필요한 세미콜론 (Head First C Example, Griffiths & Griffiths 2012)

"Head First Diner의 웨이터 버스 테이블을 돕는 새로운 프로그램이 있습니다.이 코드는 자동으로 청구서를 합산하고 각 품목에 판매 세를 추가합니다. 필요한 것을 알아낼 수 있는지 확인하십시오. 각 공백에 "

오류는 줄 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); 
} 
+3

네, 맞습니다. 세미 올론은 거기 있으면 안된다. –

+0

일부 오타가 편집하지 못하게하는 것은 드문 일이 아닙니다. 많은 논픽션 책 (특히 컴퓨터 관련 텍스트 북용)은 * 에라타 * 목록 문제를 가질 수 있습니다. 또한 이러한 오류가 수정되었을 수있는 최신판을 찾아야합니다. –

+0

확인 된 정오표 : http://www.oreilly.com/catalog/errata.csp?isbn=0636920015482 –

답변

1

예, 구문 오류입니다. float add_with_tax(float f);은 유효한 프로토 타입이므로 파일 범위에서 유일한 블록 { ... }을 가질 수 없으므로 실제 오류는 다음 행에 있습니다.