user-0 提问: 哪里错了？该怎么改？

回复:
user: user-1
content: 按我的写就对了 #include <stdio.h> #include <time.h>  int main() {   int i = 0, x, r, get = 0, lost = 0, number;   int t1 = 0, t2 = 0;   char option, go;    do {     i++;     srand(time(0));     x = rand() % 12 + 1;     printf("=======================================================\n");     printf("Guesses Choice:\n");     printf("O-Odd E-Even L-Low M-Medium H-High N-Number\n");     printf("=======================================================\n");     printf("Enter your choice: ");     scanf("%c", &option);     getchar();     printf("Point at risk: ");      scanf("%d", &r);          switch (option) {                   case 'O':       case 'o':         printf("Odd number\n");         if( (x % 2) == 1) get = r;           else lost = r;         break;       case 'E':       case 'e':         printf("Even number\n");         if( (x % 2) == 0) get = r;           else lost = r;         break;       case 'L':       case 'l':         printf("Low number\n");         if(x <= 4) get = 2 * r;           else lost = r;         break;       case 'M':       case 'm':         printf("Medium number\n");         if(x >= 5 && x <= 8) get = 2 * r;           else lost = r;         break;       case 'H':       case 'h':         printf("High number\n");         if(x >= 9) get = 2 * r;           else lost = r;         break;       case 'N':       case 'n':         printf("A number\n");         printf("Enter your number: \n");         scanf("%d", &number);         if(x == number) get = 12 * r;           else lost = r;         break;       default:         printf("Try again!\n www.xlongjt.com");     }      printf("The winning number is %d.\n", x);     if(get > 0) printf("You won %d points.\n", get);    	  else printf("You lost %d points.\n", lost);    	t1 += get;    	t2 += lost;     printf("Continue (Y/N)? ");     scanf("%c", &go);     getchar();   } while (go == 'Y' || go == 'y');   printf("Total number of guesses: %d\n", i);   printf("Your current point: %d\n", t1 - t2);   system("pause"); }

user: user-2
content: scanf( "%c", &r); 只是读入一个字符,而你在输入时实际上输入的是:某个字符+Enter,Enter 产生的'\n' 也会停留在输入缓冲区中,下次调用 scanf( "%c", &number);或者scanf("%c", &go);时就会直接读到 ‘\n’ 而不是等待你再次输入! 因此，在scanf("%d", &r); 和 scanf("%d", &number); 后加getchar(); 即可。

user: user-3
content: 在每个最后不带\n的printf后面加fflush(stdout); 在每个不想受接收缓冲区旧内容影响的scanf前面加rewind(stdin); 另外请检查scanf的返回值。 //请今后要用 int c; scanf("%c",&c); //时，都改为 char s[2]; int c; scanf("%1s",s); c=s[0];

user: user-4
content: 少了一个#include <stdlib.h> 然后再所有要输入，但是可能输入错误的地方再输入后，加上清空输入缓冲区fflush(stdin)   #include <stdio.h> #include <stdlib.h> #include <time.h>  int main() {   int ret;   int i = 0, x, r, get = 0, lost = 0, number;   int t1 = 0, t2 = 0;   char option, go;    do {   	//这里加一个    	fflush(stdin);     i++;     srand(time(0));     x = rand() % 12 + 1;     printf("=======================================================\n");     printf("Guesses Choice:\n");     printf("O-Odd E-Even L-Low M-Medium H-High N-Number\n");     printf("=======================================================\n");     printf("Enter your choice: "); 	scanf("%c", &option); 	 	//这里加一个 	fflush(stdin);	 	//getchar();      printf("Point at risk: ");      ret = scanf("%d", &r);          //如果输入的不是数字，就清除输入流缓冲      if (ret == 0)     { 		fflush(stdin); 	}          switch (option) {                   case 'O':       case 'o':         printf("Odd number\n");         if( (x % 2) == 1) get = r;           else lost = r;         break;       case 'E':       case 'e':         printf("Even number\n");         if( (x % 2) == 0) get = r;           else lost = r;         break;       case 'L':       case 'l':         printf("Low number\n");         if(x <= 4) get = 2 * r;           else lost = r;         break;       case 'M':       case 'm':         printf("Medium number\n");         if(x >= 5 && x <= 8) get = 2 * r;           else lost = r;         break;       case 'H':       case 'h':         printf("High number\n");         if(x >= 9) get = 2 * r;           else lost = r;         break;       case 'N':       case 'n':         printf("A number\n");         printf("Enter your number: \n");         scanf("%d", &number);         if(x == number) get = 12 * r;           else lost = r;         break;       default:         printf("Try again!\n");     }      printf("The winning number is %d.\n", x);     if(get > 0) printf("You won %d points.\n", get);    	  else printf("You lost %d points.\n", lost);    	t1 += get;    	t2 += lost;     printf("Continue (Y/N)? \n");     //getchar();     fflush(stdin); 	scanf("%c", &go);        } while (go == 'Y' || go == 'y');   printf("Total number of guesses: %d\n", i);   printf("Your current point: %d\n", t1 - t2);   system("pause"); }