-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberGuessingGame.c
38 lines (32 loc) · 955 Bytes
/
NumberGuessingGame.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
const int MIN = 1; // This is the minimum number that we will generate when we generate a random number
const int MAX = 100; // This is the maximum number that we will generate when we generate a random number
int guess;
int guesses;
int answer;
srand(time(0)); // Uses the current time as a seed
answer = (rand() % MAX) + MIN; // Generates a random number between MIN and MAX
do{
printf("Enter a guess: ");
scanf("%d", &guess);
if(guess > answer)
{
printf("Too high!\n");
}
else if(guess < answer)
{
printf("Too low!\n");
}
else{
printf("CORRECT!\n");
}
guesses++;
}while(guess != answer);
printf("answer: %d\n", answer);
printf("guesses: %d\n", guesses);
return 0;
}