From c378dd8139d408732a264f64c0741a97314fc979 Mon Sep 17 00:00:00 2001 From: fdlt3859 Date: Wed, 25 Jan 2023 10:46:20 +0000 Subject: [PATCH] The Round 4 now takes input and tracks score --- src/main/quizproject.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/quizproject.c b/src/main/quizproject.c index 8ad051e..bd84bfa 100644 --- a/src/main/quizproject.c +++ b/src/main/quizproject.c @@ -189,24 +189,30 @@ void ask_hard_questions(void) { }; char answers[NUM_QUESTIONS] = { 'B', 'A'}; // correct answers (A, B, C, or D) - char user_answers[NUM_QUESTIONS]; // to store user answers (A, B, C, or D) for (int i = 0; i < 2; i++) { - - + printf("[%d] %s\n", i + 1, questions[i]); for (int j = 0; j < 4; j++) { printf("%s\n", options[i][j]); - - } - - } - - + printf("Enter your answer (A, B, C, or D): "); + char response; + scanf(" %c", &response); + response = toupper(response); + user_answers[i] = response; + // check each answer + if (user_answers[i] == answers[i]) { + score++; + correct(score); + } else { + wrong(score); + } + } k++; } + printf("\nYour final score: %d\n", score); } @@ -217,7 +223,7 @@ void hint(int question_num) { printf("%s\n",qC[question_num]); } -void displayThankYouMessage(void) { // 4 & 5 +void displayThankYouMessage(void) { printf("*******************************\n"); printf("Thank you for playing QuizGame!\n"); printf("*******************************\n\n");