猜数游戏

Posted HGR

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了猜数游戏相关的知识,希望对你有一定的参考价值。

/*猜数游戏,magic number#4,版本*/
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
int magic;/*magic number*/
int guess;/*user\'s number*/
int guessnum,response=1;
time_t t;
printf("\\nWelcome to the magic number game\\n");
srand((unsigned int)time(&t));/*产生随机数*/
do
{
magic=rand()%101;/*产生1到100之间的随机数*/
guessnum=1;/*guessnum的初始值为1*/
while(guessnum<=3)/*未猜满3次,继续猜*/
{
printf("\\nGuess the magic number:");
scanf("%d",&guess);/*输入第一个猜的数*/
if(guess==magic)
{

printf("***Right***\\n");
printf("%d is the magic number\\n",magic);
break;/*如果猜对了则跳出这个循环*/
}
else if(guess>magic)
printf("Wrong,too high\\n");
else
printf("Wrong,too low\\n");
guessnum++;/*猜错一次,guessnum便加1*/
}
if(guessnum>3)/*猜满3次则游戏结束*/
printf("Three times are wrong!\\n");
printf("\\nEnter \'0\' to quit or other to start a new game or:");
scanf("%d",&response);
}while(response!=0);
printf("\\nGame Over!\\n");
system("PAUSE");
return 0;

} /*end main*/

以上是关于猜数游戏的主要内容,如果未能解决你的问题,请参考以下文章

bzoj1594猜数游戏

猜数游戏

猜数游戏

猜数小游戏升级版(IO流实现,对IO流进行加强理解运用)

猜数游戏

22.猜数游戏