Browse Source

Created Word guessing game

main
fdlt3859 2 years ago
parent
commit
4cd37a96c6
  1. 49
      src/main/quizproject.c
  2. 3
      src/main/quizproject.h

49
src/main/quizproject.c

@ -536,6 +536,46 @@ void play_guessingGame() {
printf("****************************************\n"); printf("****************************************\n");
} }
void play_guessTheWord() {
char word[] = "Fulda";
char guessed[MAX_WORD_LENGTH] = {0};
int lives = MAX_LIVES;
int word_length = strlen(word);
char guess;
guess = toupper(guess);
while (lives > 0) {
int i;
int correct = 0;
printf("Lives: %d\n", lives);
printf("Guess a letter: ");
scanf(" %c", &guess);
for (i = 0; i < word_length; i++) {
if (word[i] == guess) {
guessed[i] = guess;
correct = 1;
}
}
if (!correct) {
lives--;
}
if (strcmp(word, guessed) == 0) {
printf("You win! The word was: %s\n", word);
break;
}
}
if (lives == 0) {
printf("You lose! The word was: %s\n", word);
}
}
void feedbackForm(void){ void feedbackForm(void){
int rating; int rating;
char feedback[1000]; char feedback[1000];
@ -591,13 +631,14 @@ int main() {
int jump_to_menu = 0; int jump_to_menu = 0;
while (choice != 5 || jump_to_menu) {
while (choice != 6 || jump_to_menu) {
printf("Welcome to the Game Menu!\n"); printf("Welcome to the Game Menu!\n");
printf("1. QuizGame\n"); printf("1. QuizGame\n");
printf("2. Fact or Lie?\n"); printf("2. Fact or Lie?\n");
printf("3. Who wants to be a millionaire\n"); printf("3. Who wants to be a millionaire\n");
printf("4. Guess the Number!\n"); printf("4. Guess the Number!\n");
printf("5. Exit\n");
printf("5. Guess the Word!\n");
printf("6. Exit\n");
printf("Enter your choice: "); printf("Enter your choice: ");
scanf("%d", &choice); scanf("%d", &choice);
@ -619,6 +660,10 @@ int main() {
jump_to_menu = 1; jump_to_menu = 1;
break; break;
case 5: case 5:
play_guessTheWord();
jump_to_menu = 1;
break;
case 6:
printf("\nThank you for trying our C code!\n"); printf("\nThank you for trying our C code!\n");
break; break;
default: default:

3
src/main/quizproject.h

@ -5,6 +5,7 @@ void play_quizgame(void);
void play_factorlie(void); void play_factorlie(void);
void play_milliongame(void); void play_milliongame(void);
void play_guessingGame(void); void play_guessingGame(void);
void play_guessTheWord(void);
void displayWelcomeMessage(void); void displayWelcomeMessage(void);
void displayGameInstructions(void); void displayGameInstructions(void);
void displayLifelineInstructions(void); void displayLifelineInstructions(void);
@ -29,5 +30,7 @@ void v_guessingGame(void);
#define NUM_QUESTIONS 5 #define NUM_QUESTIONS 5
#define round 3 #define round 3
#define MAX_LIVES 10
#define MAX_WORD_LENGTH 20
#endif #endif
Loading…
Cancel
Save