#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int Menu(){
printf("1.开始游戏\n");
printf("0.结束游戏\n");
printf("请输入您的选择\n");
int choice = 0;
scanf("%d", &choice);
return choice;
}
void Game(){
srand((unsigned int)time(0));
int result = rand() % 100 + 1;
while (1){
printf("请输入要猜的数字:");
int num = 0;
scanf("%d", &num);
if (num < result){
printf("低了\n");
}
else if (num > result){
printf("高了\n");
}
else {
printf("恭喜您猜对了\n");
break;
}
}
}
int main(){
while (1){
int choice = Menu();
if (choice == 1){
Game();
}
else {
printf("游戏结束\n");
}
}
system("pause");
return 0;
}
猜数字游戏(函数)
猜你喜欢
转载自blog.csdn.net/weixin_43508555/article/details/84147259
今日推荐
周排行