|
|
#2
rjsp2019-12-06 09:15
|
#include<stdio.h>。如果用户猜对了,且猜的次数在5次以下,则输出“Good”,猜的次数在5~8次输出“Not bad”,否则输出“You can do better”
这是书上的一道练习题,我的程序不能同时输入多个数和产生的随机数比较,而且后面count前面的else不加if没有用,请问一下大佬这个怎么改,或者给我一种新的解题方法,谢谢各位大佬了!



#include<stdlib.h>
#include<time.h>
int main()
{
int n, i = 1;
int x = 0, count = 0;
srand((unsigned int) time(NULL));
x = rand() % 100;
printf("%d ", x);
printf("输入任意整数n:");
scanf("%d", &n);
if (x > n)
{
printf("low\n");
}
count++;
if (x < n)
{
printf("high\n");
}
count++;
if (count < 5)
printf("Good\n");
if (count >= 5 && count <= 8)
printf("Not bad\n");
else
printf("You can do better\n");
return 0;
}
程序代码: