-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay2_Guess_a_number.c
More file actions
65 lines (49 loc) · 1.4 KB
/
Copy pathDay2_Guess_a_number.c
File metadata and controls
65 lines (49 loc) · 1.4 KB
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
#include <stdio.h>
#include <time.h>
void intro(char name[100],int random){
printf("\tWelcome to Mini Game\n");
printf("\t Guessing a number\n");
printf("\t made By ForstSaw\n\n\n\n");
printf("Hello,Can u tell your name before we started : ");
gets(name);
printf("Ok %s,before we started,please input the range of number: ",name);
scanf("%d",&random);
printf("so i am thinking of a number between 1 - %d\n",random);
Takeguess(random);
}
void Takeguess(int random){
srand(time(NULL));
int randoms = (rand()%random)+1;
int i;
int guess;
int len = 0;
printf("\nI will give you 3 times chance to guess it\ngoodluck \n\n");
for(i =0;i < 3;i++){
printf("Take a guess: ");
scanf("%d",&guess);
if(guess == randoms){
printf("Nice Guess\n");
break;
}
else if(guess > randoms){
printf("your guess is too high\n");
}
else if(guess < randoms){
printf("your guess is too low\n");
}
len++;
}
if(guess == randoms){
printf("\nyou guessed my number well\n");
}
else{
printf("\nSorry,My number is %d\n",randoms);
}
printf("Game Over\n");
}
int main(){
char name[100];
int random;
intro(name,random);
return 0;
}