用C写的一个小游戏.有一点问题.大家来看下
用C写了一个猜数学的小游戏.程序默认一个数字为30.用户输入一个数字.如果是大于30,程序提示用户大了,如果小于30.程序提示小了.如果输为的为30则告诉用户赢了.
下面是源程序:
#include <stdio.h>
#define GOAL 30
void main()
{
int data;
int count;
count=0;
printf("please input the number:");
scanf("%d",&data);
do
{
if(data<GOAL)
printf("the number is small than GOAL");
else if(data>GOAL)
printf("the number is big than GOAL");
else
printf("you win");
count ++;
}while(data!=GOAL);
printf("you have guess %d times ",count);
}
运行时发现当我输入数字时,结果非预期.出现很多代码.不停的刷屏.按任何键都没有用.是不是进了死循环.
我检查了程序,没有发现问题啊.有没有哪个看得出来其中的错误.