-
Notifications
You must be signed in to change notification settings - Fork 0
/
numberGame.c
64 lines (63 loc) · 1.39 KB
/
numberGame.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
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
void menu()
{
printf("*****************************\n");
printf("***********1.Play************\n");
printf("***********0.Exit************\n");
printf("*****************************\n");
}
void game()
{
// srand((unsigned int)time(NULL));
/*if the speed of generating random number is too fast,
adjacent repeating random numbers will appear
*/
int pseudo_rand=rand()%100+1;//1-100
int res;
while (1)
{
printf("Please enter a number between 1 and 100:");
scanf("%d",&res);
if (res<pseudo_rand)
{
printf("The number %d you guess is too small.\n",res);
}
else if(res>pseudo_rand)
{
printf("The number %d you guess is too big.\n",res);
}
else
{
printf("Congratulations!\n");
break;
}
}
}
int main_28()
{
int input=0;
srand((unsigned int)time(NULL));
do
{
menu();
printf("Please enter your choice 1/0:\n");
scanf("%d",&input);
switch (input)
{
case 1:
game();
break;
case 0:
printf("Quit game.\n");
break;
default:
printf("Error,please try again!\n");
break;
}
}
while (input);
return 0;
}