#include <stdio.h> #include <ctype.h> int main(int argc,char **argv) { char ch; printf("Enter the want you want:\n"); while((ch = getchar()) != '#') { if(ch == '\n') continue; //改爲break的話,直接回車就會跳出循環。 if(islower(ch)) switch(ch) { case 'a':puts("a");break; case 'b':puts("b");break; case 'c':puts("c");break; case 'd':puts("d");break; default:printf("gameover.\n"); } else printf("simple.\n"); while(getchar() != '\n') //很經典的清空輸入行 continue; printf("try again.\n"); } printf("bye.\n"); return 0; }