|
안녕하세요? 레조입니다.
예전에 C로 프로그래밍을 할때는 선언이전에 어떤 작업을 하면 컴파일이 않되었습니다.
그 때문에 c와 cpp의 차이로 컴파일 방식이 C 또는 C++로 차이가 생기고 이렇게되면서
선언 이전에 어떤 처리가 있으면 C방식에서는 오류가 나게됩니다.
즉, clrscr();을 선언문 아래로 빼내면 두 타입에서 문제없이 작동하게 됩니다.
: char *name,*num; <----------- 여기서.에러
: int kor,eng,math,sci,phy; <------------- 여기서에러
: float total1,total2,avg1,avg2; <--------- 여기서 에러
: clrscr();
clrscr()을 아래로 내려보세요.
선언시에는 화면에 영향을 주지 않으니 그 이후부터 처리해도 결과에는 차이가
없습니다.
선녀 님이 쓰신 글 :
: **.c 하고 **.cpp 하고 다른 가봐여..
: 똑같은 소스를 c로 저장해서 컴파일 하면 에러가 나고 cpp로 저장하면 에러 없이 잘 돌아가니..
: 이 소스가 그렇던데.. 왜 그런지..설명좀 부탁해여..
:
: Declaration is not allowed here
: Declaration is not allowed here
: Declaration is not allowed here
:
: 이렇게 에러 코드가 나오네여..
:
: #include <stdio.h>
: #include <conio.h>
: void main(void)
: {
: clrscr();
: char *name,*num; <----------- 여기서.에러
: int kor,eng,math,sci,phy; <------------- 여기서에러
: float total1,total2,avg1,avg2; <--------- 여기서 에러
: gotoxy(40,5); printf("score");
: gotoxy(23,7); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
: gotoxy(25,9);
: printf("input name : "); scanf("%s",name);
: gotoxy(25,10);
: printf("input number : "); scanf("%s",num);
: gotoxy(16,11);
: printf("input First kor, eng, math, sci, phy :");
: scanf("%d %d %d %d %d",&kor,&eng,&math,&sci,&phy);
: total1=kor+eng+math+sci+phy;
: avg1=total1/5;
: gotoxy(16,12);
: printf("input Second kor, eng, math, sci, phy :");
: scanf("%d %d %d %d %d",&kor,&eng,&math,&sci,&phy);
: total2=kor+eng+math+sci+phy;
: avg2=total2/5;
: gotoxy(23,14); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
:
: gotoxy(25,15);
: printf("name : %s\t",name); printf("number : %s\n",num);
: gotoxy(25,16);
: printf("First total : %.0f , average : %.2f",total1,avg1);
: gotoxy(25,17);
: printf("Second total : %.0f , average : %.2f",total2,avg2);
: gotoxy(23,19);
: printf("=======================================");
: gotoxy(25,21);
: printf("total sum : %.0f , average : %.2f",total1+total2,(avg1+avg2)/2);
: getch();
: }
:
:
:
|