#6225: 請教一下為何我一直CE???


qaz40417 (默默無語★)


#include<stdio.h>
main()
{
int M,D,S;
while(scanf("%d %d",&M,&D));
S=(M*2+D)%3;
if(S=0)
{
printf("普通\n");
else if(S=1)
{
printf("吉\n");
else
printf("大吉\n");
}
system("pause");
return 0;
}

 

 程式新手0.0 但我認為我沒錯阿....... 請教一下大大們@@"

#6227: Re:請教一下為何我一直CE???


leopan0922 (zz)


#include
main()
{
int M,D,S;
while(scanf("%d %d",&M,&D));
S=(M*2+D)%3;
if(S=0)
{
printf("普通\n");
else if(S=1)
{
printf("吉\n");
else
printf("大吉\n");
}
system("pause");
return 0;
}

 

 程式新手0.0 但我認為我沒錯阿....... 請教一下大大們@@"


我記得system("pause");

要include<stdlib.h> 

#6229: Re:請教一下為何我一直CE???


dark4491 (小強爆走傳說)


#include
main()
{
int M,D,S;
while(scanf("%d %d",&M,&D));
S=(M*2+D)%3;
if(S=0)
{
printf("普通\n");
else if(S=1)
{
printf("吉\n");
else
printf("大吉\n");
}
system("pause");
return 0;
}

 

 程式新手0.0 但我認為我沒錯阿....... 請教一下大大們@@"

我看到有幾個錯

*while後面不用加分號 

*在這個網站裡    不用加system("pause");   因為包在while裡面了       就不需要 system("pause")

而且    這個好像是禁用函式 

 

*scanf("%d %d",&M,&D)!=EOF

* 誇號的分配有問題

我幫你改完後

 #include<stdio.h>

main()

{

int M,D,S;

while(scanf("%d %d",&M,&D)!=EOF)

{

S=(M*2+D)%3;

if(S==0)

{

printf("普通\n");

}

else if(S==1)

{

printf("吉\n");

}

else

{

printf("大吉\n");

}

}

return 0;

}

 
看不懂再問我吧  : ) 
#8336: Re:請教一下為何我一直CE???


cliff75426 (阿鎧)


不好意思  請問為何要加   !=EOF ??

 


#8337: Re:請教一下為何我一直CE???


rosynirvana (rosynirvana)


不好意思  請問為何要加   !=EOF ??

 



http://www.cplusplus.com/reference/cstdio/scanf/

请参考return value部分