-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguess game.c
67 lines (60 loc) · 1.06 KB
/
guess game.c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// generates a random number and guess random number
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void menu()
{
printf("********************************\n");
printf("**** 1. play 0. exit ****\n");
printf("********************************\n");
}
void game()
{
int ret = 0;
int guess = 0;
//timestamp
ret = rand() % 100 + 1; //generate a ranfom number from 1-100
while (1)
{
printf("please guess number\n");
scanf("%d", &guess);
if (guess > ret)
{
printf("too much\n");
}
else if (guess < ret)
{
printf("too little\n");
}
else
{
printf("congratulations, you guessed right\n");
break;
}
}
}
int main()
{
int input = 0;
srand((unsigned int)time(NULL));
do
{
menu();
printf("please select>:");
scanf("%d", &input);
switch (input)
{
case 1:
game(); //play game
break;
case 0:
printf("exit game\n");
break;
default:
printf("select error\n");
break;
}
} while (input);
return 0;
}