-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.c
34 lines (30 loc) · 813 Bytes
/
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
// including all libraries.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// main function
int main(){
int number , guess , nguesses=1 ;
srand(time(0));
number = rand()%100 + 1 ; // generates a random number between 1-100
// printf("The number is %d\n", number);
// Keep running the loop until the number is guessed
do
{
printf("Guess the number between 1-100\n");
scanf("%d",&guess);
if (guess>number)
{
printf("Lower number please\n");
}
else if (guess<number)
{
printf("Higher number please\n");
}
else{
printf ("You guessed it in %d attempts\n", nguesses);
}
nguesses++;
} while (guess!=number);
return 0;
}