-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUESSING_NUM_GAME.c
36 lines (31 loc) · 1.13 KB
/
GUESSING_NUM_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
// generate random number using rand() function
//number = ran()%100 + 1;
//this work as any random number will divide by 100 the answer will be in 0 to 100
#include<stdio.h>
#include<stdlib.h> // To use rand() function
#include<time.h> // To use time(0) function
int main()
{
int number, guess, nguesses=1; // guess is number that is generated & nguesses is used for no of time you guessed the number while playing
srand(time(0)); //random numbers for every output
number = rand()%100 + 1; //generate random number between 1 to 100 if we take 200 instead of 100 number will generate number between 1 to 200.
//printf("the number is %d",number);
//keep running the loop until it guesed
do
{
printf("Guess the number between 1 to 100\n");
scanf("%d",&guess);
if(guess>number){
printf("lower number please!!\n");
}
else if(guess<number){
printf("Highest number please!!\n");
}
else{
printf("you guess it in %d attempts\n", nguesses);
}
nguesses ++;
}
while(guess!=number);
return 0;
}