#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void Game() {
// 生成随机数
// 0-32767
srand((unsigned int)time(0));
int result = rand() %100 +1;
int num = 0;
while (1) {
printf("请输入要猜的数字!\n");
scanf("%d", &num);
if (num < result) {
printf("低了!\n");
}
else if (num > result) {
printf("高了!\n");
}
else {
printf("猜中了!\n");
break;
}
}
}
int main() {
printf("请输入您的选择!1:开始游戏 0:结束游戏 \n");
int choice;
scanf("%d", &choice);
if (choice == 1) {
Game();
}
else {
printf("googbye!");
}
system("pause");
return 0;
}
利用计算机产生随机数,让用户猜这个随机数的值
猜你喜欢
转载自blog.csdn.net/qq_43508801/article/details/83745789
今日推荐
周排行