-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment5.c
More file actions
48 lines (39 loc) · 1.27 KB
/
Copy pathAssignment5.c
File metadata and controls
48 lines (39 loc) · 1.27 KB
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
42
43
44
45
46
47
48
#include <stdio.h>
#include <string.h>
char word[7] = "HANGMAN", your_word[7];
void displayWord() {
printf("_ _ _ _ _ _ _\n");
}
void playGame(int chances) {
for (int i = 1; i <= 3; i++) {
printf("\nEnter your guess (word): ");
scanf("%s", your_word);
if (strcmp(your_word, word) == 0) {
printf("Congratulations! Your guess is correct. The word is HANGMAN.\n");
return;
} else {
chances--;
if (chances > 0) {
printf("Incorrect! You have %d chances left.\n", chances);
} else {
printf("No chances left. You lose! The word was HANGMAN.\n");
return;
}
}
}
}
int main() {
int n;
printf("Welcome to the Hangman Game!\n");
printf("Press any number between 0-9 to start: ");
scanf("%d", &n);
printf("\nInstructions:\n");
printf("1. A word is given with hidden characters. Guess the word.\n");
printf("2. Enter the full word (not just a character).\n");
printf("3. You have 3 chances.\n");
printf("4. Use UPPERCASE letters only.\n");
printf("\nThe word you need to guess looks like this:\n");
displayWord();
playGame(3);
return 0;
}