-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomNumGenerator.c
More file actions
41 lines (41 loc) · 1023 Bytes
/
RandomNumGenerator.c
File metadata and controls
41 lines (41 loc) · 1023 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int number, guess, newGame;
start:
srand(time(0));
number = rand() % 100 + 1; // Generate random number between 1 and 100
// printf("The Number is %d\n", number);
// Keep running the loop until the number
int nguesses = 1;
system("cls");
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("Higher number please!\n");
}
else
{ printf("You guessed it in %d attempts\n", nguesses);
}
nguesses++;
} while (guess != number);
printf("NEW GAME press 1\n");
printf("EXIT GAME press 2\n");
scanf("%d",&newGame);
if (newGame == 1){
system("cls");
goto start;
}
else {
time(10);
exit;
}
return 0;
}