Subject requirements:
1. The system randomly generates an integer between 0 and 99 (including 0 and 99);
2. The player enters an integer, and the system prompts the relationship between the value and the random number according to the value entered by the player for the player's reference;
3. If the player fails to guess correctly ten times in a row, he will decide whether to enter the next round of guessing game according to his choice.
[Summary of running problems] The random number generated by the rand() function is a "pseudo-random number", and the random number (group) generated every time the program is run is the same: this is where the v2.1 version should be optimized.
#include<stdio.h>
#include<stdlib.h>
void f()//用户抽奖流程
{
int magic;
int guess;//记录用户输入的数
char i;//循环控制变量
char flag='Y';
printf("猜数游戏开始!\n");
while(flag=='Y')
{
i=0;
magic=rand()%100;//生成一个介于0~99之间的整数(包括0和99)
printf("当前次数:\n");
while(i<10)
{
printf("%d. 请输入一个介于0~99之间的整数: ", i+1);
scanf("%d", &guess);
if(guess==magic)
{
printf("猜对了!\n");
break;
}
else if(guess<magic)
{
printf("猜小了.\n");
}
else
{
printf("猜大了.\n");
}
i++;
}
printf("请选择是否进入下一轮猜数游戏(Y/N): ");
scanf(" %c", &flag);
}
//
printf("欢迎您下次再来!\n");
//
return ;
}
int main()
{
f();
return 0;
}