-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber.c
More file actions
39 lines (29 loc) · 934 Bytes
/
number.c
File metadata and controls
39 lines (29 loc) · 934 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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
char play_again;
do {
srand(time(NULL));
int target_number = rand() % 100 + 1;
int guess;
do {
// Get user input
printf("Your answer (1-100): ");
scanf("%d", &guess);
// Check if the guess is correct
if (guess == target_number) {
printf("Correct! The number was %d\n", target_number);
break;
} else if (guess < target_number) {
printf("\nToo low.\n");
} else {
printf("\nToo high.\n");
}
} while (1);
// Ask if the user wants to play again
printf("Do you want to play again? (y/n): ");
scanf(" %c", &play_again);
} while (play_again == 'y' || play_again == 'Y');
return 0;
}