- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- main(){
- int count , number , guess ;
- char yes = 'Y';
- printf("\\n now let us play the game ,\\n Guess the number");
- srand((int)time(0));
- number = 1+(int)(100.0*rand()/(RAND_MAX+1.0));
- //如果想偷懒 这里显示答案
- //printf("%d\\n", number);
- count=0;
- do{
- do{
- printf("\\n Input an integer number(1-100): ");
- scanf("%d",&guess);
- }while(!(guess>1 && guess <=100));
- if (guess==number)
- {
- printf("\\ngongxi ni caidui le thank you");
- yes ='N';
- number = 1+(int)(100.0*rand()/(RAND_MAX+1.0));
- //如果想偷懒 这里显示答案
- //printf("%d\\n", number);
- printf("\\nNEXT?(Y/N):");
- scanf("%s",&yes);
- }else{
- do
- {
- if (guess<number)
- printf("\\nYour answer is LOW ,try again\\n");
- if (guess>number)
- printf("\\nYour answer is high ,try again\\n");
- count++;
- } while (guess==number);
- if (count==15)
- {
- printf("\\n That is the %d time ! think is hard next!");
- exit(0);
- }
- if (count<=7)
- {
- printf("\\n You have got it in %d times \\n",count);
- printf("\\n Congretulations");
- }else{
- printf("\\n You got it in %d times \\n",count);
- printf("\\n bet you can do it better");
- }
- }
- }while(toupper(yes)=='Y');
- }
- //该片段来自于http://www.codesnippet.cn/detail/130220148719.html
来源: http://www.codesnippet.cn/detail/130220148719.html