-
Notifications
You must be signed in to change notification settings - Fork 12
/
guess.c
27 lines (23 loc) · 913 Bytes
/
guess.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
#include <stdio.h>
/*
* This program is a simple number guessing game where the user tries to guess a number
* between 0 and 9. The program checks if the guessed number matches the corresponding
* value in a predefined array. After each round, the user is asked if they want to play again.
*/
int main() {
int nums[] = {0, 9, 7, 3, 4, 8, 1, 2, 0, 6};
int input_selected;
char play_again;
do {
char msg[] = "This is simple!\nTry to guess a number between 0 and 9.\n";
printf("%s", msg);
printf("Enter your guess: ");
scanf("%d", &input_selected);
if (input_selected >= 0 && input_selected < 10) {
if (input_selected == nums[input_selected]) {
printf("You Won!\n");
} else {
printf("You Lost!\n");
}
} else {
printf("Please enter a number between 0 and 9.\n");