简单的猜数字出错。求修改
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
int count,number,guess;
char yes='Y';
printf("\nNow let us play the games:\nGuess the number");
while(toupper(yes)=='Y')
{
count=0;
randomize();
number=random(100)+1;
do{
do{
printf("\nInput an number(1_100)");
scanf("%d",&guess);
}while(guess>=1&&guess<=100);
if(number>guess)
printf("\nYour answer is low,try again");
else
printf("\nYour answer is high,try again");
count++;
if(count==15)
{
printf("\nThis is the %d times!thank it hard next!\nright number is %d",count,number);
exit(0);
}
}while(guess!=number);
if(count<=7)
{printf("\nYou have got int in %d time.\n",count);printf("Congretulations!");}
else {
printf("\nYou have got int in %d time.\n",count);
printf("\n I bet you can do it better");
}
printf("\n NEXT?(Y/N):");scanf("%c",&yes);
}
return 0;
}
[解决办法]
换srand和rand试试
[解决办法]
srand和rand函数可以参考下面的代码