-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path猜数字.cpp
50 lines (48 loc) · 873 Bytes
/
猜数字.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
void menu() {
printf("********************************\n");
printf("******* 1. play *******\n");
printf("******* 0. exit *******\n");
printf("********************************\n");
}
void game() {
int ret = rand() % 100 + 1;
int num = 0;
//2.猜数字
while (1) {
printf("请猜数字:>");
scanf("%d", &num);
if (num == ret) {
printf("恭喜你,猜对了\n");
break;
}
else if(num>ret){
printf("猜大了\n");
}
else {
printf("猜小了\n");
}
}
}
int main() {
int input = 0;
do {
menu();
printf("请选择:>");
scanf("%d", &input);
switch (input) {
case 1:
game();
break;
case 0:
printf("推出游戏\n");
break;
default:
printf("选择错误\n");
break;
}
} while (input);
return 0;
}