#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int magic, guess, count;
int reply;
srand(time(NULL));
do
{
magic = rand() % 500 + 1;
count = 0;
do
{
printf("请猜一个0~500之间的整数:");
scanf("%d", &guess);
count++;
if (guess>magic)
printf("猜大了~\n");
else if (guess < magic) //else只和与其紧紧相连的前一个if构成一对
printf("猜小了~\n");
else
printf("厉害!猜对了!\n");
} while (guess != magic && count < 10);
printf("一共猜了%d次\n", count);
printf("继续请按数字1键,按其他键退出~\n");
scanf("%d", &reply);
} while (reply == 1);
return 0;
}