标签:print 猜数字游戏 define rand clu pause 随机 初始化 ret
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void Game()
{
int toGuess = rand() % 100 + 1;
while (1){
printf("请输入一个整数(1-100):");
int num = 0;
scanf("%d", &num);
if (num < toGuess){
printf("低了\n");
}
else if (num > toGuess){
printf("高了\n");
}
else{
printf("恭喜你,猜对了!\n");
break;
}
}
}
int Menu(){
{
printf("===============\n");
printf("1. 开始游戏\n");
printf("0. 退出游戏\n");
printf("===============\n");
printf("请输入您的选择:");
int choice = 0;
scanf("%d", &choice);
return choice;
}
}
int main()
{
srand(time(0));//讲随机数初始化,达到不会重复数字的目的
while (1){
int choice = Menu();
if (choice == 1){
Game();
}
else{
printf("goodbye!\n");
break;
}
}
system("pause");
return 0;
}
标签:print 猜数字游戏 define rand clu pause 随机 初始化 ret
原文地址:https://www.cnblogs.com/Leafbud/p/12554608.html