-
Notifications
You must be signed in to change notification settings - Fork 37
/
game.c
35 lines (30 loc) · 794 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
35
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int number, guess, nguesses = 1;
srand(time(0));
number = rand() % 100 + 1; //Generates a random number b/w 1 and 100
// printf("The number is %d \n", number);
//keep running the loop until the number is guessed
do
{
printf("Enter the number between 1 to 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 guesses it in %d attempts\n", nguesses);
}
nguesses++;
} while (guess != number);
return 0;
}