#include
#include
#include
#include
#include
int main(void)
{
unsigned int max = 3;
unsigned int guess = 0;
unsigned int chones = 0;
unsigned int limit = 20;
char answer = 'n';
printf("这是一个猜数字游戏!游戏开始时!\n");
srand(time(NULL));
while(true)
{
chones = 1 + rand() % limit;
printf("这是一个猜数字游戏(范围1~20)\n");
for( unsigned int count = max ; count > 0 ; count-- )
{
printf("你还有%u 次机会!\n", count);
scanf("%u",&guess);
if(guess == chones)
{
printf("恭喜你猜对了!\n");
break;
}
if(guess < 1||guess > 20)
printf("请输入正确范围(1~20)\n");
else
printf("对不起!你猜错了!\n");
}
printf("程序结束!你没有猜对!这个数是:%u 继续? (Y or N)\n",chones);
scanf(" %c", &answer);
if(tolower(answer) == 'n')
break;
}
printf("程序结束!\n");
return 0;
}
这是一个猜数字游戏,共有3次机会,3次猜不到提示幸运数字并询问是否继续
问题1: 假如第一次猜对了,执行了break; 那么程序跳转到哪?
问题2: 幸运数字是怎么随着所猜的次数变化而变化的?
问题3:这两行语句unsigned int max = 3;for( unsigned int count = max ; count > 0 ; count-- )改为unsigned int count = 0;for(unsigned int i = 1 ; i <= count ; i++)后
为什么三次猜不对继续猜的时候出现问题?
望大神指教!(纸上得来终觉浅,绝知此事要躬行)