看板 C_and_CPP 關於我們 聯絡資訊
#include<stdlib.h> void main() { int i,r,d,u,l; char c; srand((unsigned)time(NULL)); do{ do{ printf("Enter upper (limit is 1 to 32767)\n"); scanf("%d",&u); while(u<=0||u>=32768){ printf("Error! Limit is 1 to 32767\n"); printf("Enter upper (limit is 1 to 32767)\n"); scanf("%d",&u); } printf("Enter lower (limit is 1 to 32767)\n"); scanf("%d",&l); while(l<=0||l>=32768){ printf("Error! Limit is 1 to 32767\n"); printf("Enter upper (limit is 1 to 32767)\n"); scanf("%d",&l); } }while(l>=u); i=rand()%(u-l)+1; while(i<=l){ i=rand()%u+1; } do{ printf("Please Enter Your Guess\n"); scanf("%d",&d); if(i==d) printf("You win\n"); else if(d<=i) printf("range is %d to %d\n",d,u); else if(d>=i) printf("range is %d to %d\n",l,d); }while(i!=d); printf("Again?(Y/N)\n"); scanf("%d%d",&c,&c); }while(c!='n'); } 這是我寫的程式 不過最後要按Y/N的時候卻怎樣都會變無窮迴圈 不知道怎辦 還有輸入的文字我想要判斷是否為數字 不過還是不行 有哪位高手可以幫助一下? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.192.84.159
zlw:scanf("%c",&c); 06/22 09:29
jacky1989:對不起喔~我蠢~因為%d打太習慣了,不過判斷數字還有問題 06/22 17:18