#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char * argv[])
{
srand((unsigned)time(NULL));
int a = rand()%100;
a+=1;
int b,c;
c = 0;
while (c < 10)
{
printf("Please enter a number: ");
if (scanf("%d", &b) == 0)
{
fprintf(stderr, "Invalid entry.\n");
return EXIT_FAILURE;
}
else
{
if (b == a)
{
printf("You are correct, the number is %d!\n", a);
printf("You used %d times to get the answer.\n", c);
break;
}
else if (b > a)
printf("The number is bigger than it suppose to.\n");
else
printf("The number is smaller than it suppose to.\n");
c++;
}
if (c == 10)
{
printf("You used 10 times, please try again!\n");
break;
}
}
return EXIT_SUCCESS;
}
温馨提示:答案为网友推荐,仅供参考