#include
#include
#include
#include
int main()
{
{
printf("********************************\n I want to play a game with you\n********************************");
}
int c;
printf("\nChoose your Rank LV1~LV3:");
scanf_s("%d", &c);
printf("\nYou have 3 chances");
int a, b;
srand(time(NULL));
if (c == 1)
{
a = 1 + (rand() % 10); //get a number from 1~10//
}
if (c == 2)
{
a = 1 + (rand() % 100); // get a number from 1~100//
}
if (c == 3)
{
a = 1 + (rand() % 1000); //get a number from 1~1000//
}
int n = 0;
while (a && n++ < 3)
{
printf("\nint a number:");
scanf_s("%d", &b);
if (a == b)
{
printf("good job\n");
break;
}
if (n != 3)
{
if (b > a)
printf("try a smaller number");
if (b < a)
printf("try a bigger number");
}
}
getchar();
return 0;
}
printf("正确数字是%d", a);
getchar();
添加在倒数第4行。