C Programming Absolute Beginner's Guide이라는 책에서 C를 배우려고했는데 문제가 생겼습니다. 나쁜 점은 질문 할 수 없다는 것입니다. 책 질문! Google에 오류를 입력하면 나를이 사이트로 안내했습니다. 내가받는 오류는 질문 제목에 있으며 이는 내 코드입니다.오류 : 예상 선언자 또는 '{'토큰 앞에 '...'토큰이 있습니다.
#include <stdio.h>
main(
{
//Set up the variables, as well as define a few
char firstInitial, middleInitial;
int number_of_pencils;
int number_of_notebooks;
float pencils = 0.23;
float notebooks = 2.89;
float lunchbox = 4.99;
//The information for the first child
firstInitial = 'J';
middleInitial = 'R';
number_of_pencils = 7;
number_of_notebooks = 4;
printf("%c%c needs %d pencils, %d notebooks, and 1 lunchbox\n",
firstInitial, middleInitial,number_of_pencils,
number_of_notebooks);
printf("The total cost is £%.2f\n\n", number_of_pencils*pencils + number_of_notebooks*notebooks + lunchbox);
//The information for the second child
firstInitial ='A';
middleInitial = 'J';
number_of_pencils = 10;
number_of_notebooks = 3;
printf("%c%c needs %d pencils, %d notebooks, and 1 lunchbox\n",
firstInitial, middleInitial,number_of_pencils,
number_of_notebooks);
printf("The total cost is £%.2f\n\n", number_of_pencils*pencills
+ number_of_notebooks*notebooks + lunchbox);
//The information for the third child
firstInitial = 'M';
middleInitial = 'T';
number_of_pencils = 9;
number_of_notebooks = 2;
printf("%c%c needs %d pencils, %d notebooks, and 1 lunchbox\n",
firstInitial, middleInitial,number_of_pencils,
number_of_notebooks);
printf("The total cost is £%.2f\n",
number_of_pencils8pencils + number_of_notebooks*notebooks + lunchbox);
return0;
}
)
이 코드의 잘못된 점은 무엇입니까?
main(
{
및 종료 :
에 오신 것을 환영처럼 보일 것입니다. 곧 [About] 페이지를 읽으십시오. 컴파일 오류가 발생하면 정확한 오류 메시지를 포함하는 것이 가장 좋습니다. 단, 파일 이름이 마일 길이가 긴 경로 인 경우 이름을 파일의 기본 이름으로 줄이십시오 (따라서'/ huge/long/path/with/many/levels/of/directory/src/file.o'에서'file.o'까지). 표시하는 소스와 그 안에있는 행 번호가 컴파일러에서 말하는 것과 일치하는지 확인하십시오. 파일이 너무 길면 편안함을 느낄 수 있습니다. MCVE ([Minimal, Complete, Verifiable Example? (http://stackoverflow.com/help/mcve)를 만드는 방법) –
나는 마지막 문자')' – Rizier123
나는 그 책의 샘플 자료를 보았는데, 그 책의 내용을 보았을 때, (2 장에서) 샘플 프로그램은 모두'int main()'(혹은'int main (void)')보다는'main()'을 가지고있다. 'return 0;을 생략 할 수있는 C99 표기법을 사용하지 않았기 때문에 필요하다. (나는 그렇게하는 코드를 좋아하지 않지만) 제 3 판은 2014 일자로되어있다. 첫 번째 프로그램은 현재 C 언어로 약 15 년 동안 쓰여지지 않았지만,'return','while','int','if'','float''을'commands '로 특성화하는 것을 싫어합니다. 키워드 : 키워드 : –