From 52cbc064398344739907f859b79bf3d24eb6ea0b Mon Sep 17 00:00:00 2001 From: fdlt3885 Date: Thu, 26 Jan 2023 11:09:16 +0000 Subject: [PATCH] Added FiftyFifty1 Function for round 4 and 5 --- src/main/quizproject.c | 60 +++++++++++++++++++++++++++++++++++++----- src/main/quizproject.h | 1 + 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/main/quizproject.c b/src/main/quizproject.c index cea2c30..fb3b73d 100644 --- a/src/main/quizproject.c +++ b/src/main/quizproject.c @@ -107,6 +107,38 @@ void fifty_fifty(int question_num) { }; printf("%s\n",qC[question_num]); } + +void fifty_fifty1(int question_num) { + char options[NUM_QUESTIONS][4][256] = { + { "A) Berlin", "B) Paris", "C) London", "D) Rome" }, + { "A) George Washington", "B) John Adams", "C) Thomas Jefferson", "D) James Madison" }, + { "A) Los Angeles Lakers", "B) Chicago Bulls", "C) Golden State Warriors", "D) Boston Celtics" }, + { "A) He", "B) H", "C) O", "D) Ne" }, + { "A) Parasite", "B) Joker", "C) Once Upon a Time in Hollywood", "D) 1917" } + }; + char correct_answer = answers[question_num]; + int num_incorrect = 0; + int incorrect_indices[2]; + for (int i = 0; i < 4; i++) { + if (options[question_num][i][0] != correct_answer) { + incorrect_indices[num_incorrect] = i; + num_incorrect++; + } + if (num_incorrect == 2) { + break; + } + } + for (int i = 0; i < 2; i++) { + options[question_num][incorrect_indices[i]][0] = '\0'; + } + // display remaining options + for (int i = 0; i < 4; i++) { + if (options[question_num][i][0] != '\0') { + printf("%s\n", options[question_num][i]); + } + } +} + void printOutOption(char qS[][100], char qC[][100],char aS[], int initial, int end, int ranArr[]){ char response; for (int i = initial; i < end; i++){ @@ -253,10 +285,9 @@ void ask_hard_questions(void) { { "A) Arthur Conan Doyle", "B) Agatha Christie", "C) Charles Dickens", "D) Stephen King" }, { "A) To Kill a Mockingbird", "B) Pride and Prejudice", "C) The Great Gatsby", "D) Jane Eyre" } }; - 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) - + char user_answers[NUM_QUESTIONS]; + int lifelines[NUM_QUESTIONS] = { 1, 1}; int randNum; for (int i = 0; i < 2; i++) { randNum = arr[i]; @@ -268,8 +299,16 @@ void ask_hard_questions(void) { char response; scanf(" %c", &response); response = toupper(response); - user_answers[randNum] = response; - // check each answer + if (response == 'F' && lifelines[i] == 1) { + fifty_fifty1(randNum); + printf("Enter your answer (A, B, C, or D): "); + scanf(" %c", &user_answers[randNum]); + user_answers[randNum] = toupper(user_answers[randNum]); + lifelines[i] = 0; + } + else { + user_answers[randNum] = response; + } if (user_answers[randNum] == answers[randNum]) { score++; correct(score); @@ -294,7 +333,16 @@ void ask_hard_questions(void) { char response; scanf(" %c", &response); response = toupper(response); - user_answers[randNum] = response; + if (response == 'F' && lifelines[i] == 1) { + fifty_fifty1(randNum); + printf("Enter your answer (A, B, C, or D): "); + scanf(" %c", &user_answers[randNum]); + user_answers[randNum] = toupper(user_answers[randNum]); + lifelines[i] = 0; + } + else { + user_answers[randNum] = response; + } // check each answer if (user_answers[randNum] == answers[randNum]) { score++; diff --git a/src/main/quizproject.h b/src/main/quizproject.h index 0d64556..482f4a9 100644 --- a/src/main/quizproject.h +++ b/src/main/quizproject.h @@ -17,6 +17,7 @@ void printOutOption(char [][100], char [][100],char [], int, int, int[] ); void looping(char [][100], char [][100], char [], int []); void displayThankYouMessage(void); int* randomNumber(); +char answers[NUM_QUESTIONS] = {'B', 'A'}; #define NUM_QUESTIONS 5