声明:此代码块不是我一人独立完成,其中的大多数来自于我的老师!
#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("2.退出游戏\n");
printf("==========================\n");
printf("请输入您的选择:\n");
int choice = 0;
scanf("%d", &choice);
return choice;
}
int main() {
srand((unsigned int) time(0));
while (1) {
int choice = Menu();
if (choice == 1) {
Game();
}
else {
printf("goodbye!\n");
break;
}
}
system("pause");
return 0;
}