我已经完成了一个程序的代码,该程序允许用户输入一系列值进行猜测,然后随机生成数字,然后允许用户猜测并报告太低、太高或正确的报告。当我测试运行程序时,我只得到“太高”的输出。我已经尝试调试并查看我的代码,但我看不出哪里出错了。任何帮助深表感谢!
#include <stdio.h>
#include <stdlib.h>
int main()
{
int min, max, number, guess, count = 0;
printf("Please enter two integers for the range:\n");
scanf("%d %d", &min, &max);
number = (min + rand()%(max - min + 1));
printf("I'm thinking of a number between %d and %d.\n", min, max);
printf("Enter your guess:\n");
scanf("%d", &guess);
while(guess != number)
{
if(guess < number)
{
count++;
printf("Too low.\n");
printf("Enter your guess:\n");
scanf("%d", &guess);
}
else
{
count++;
printf("Too high.\n");
printf("Enter your guess:\n");
scanf("%d", &guess);
}
}
count++;
printf("Correct, it took you %d tries to guess my number. ", count);
return 0;
}