From 62b2b7759c9d7976f4e06fb0dcd3bd74099d492f Mon Sep 17 00:00:00 2001 From: fdlt3914 Date: Tue, 31 Jan 2023 02:47:06 +0000 Subject: [PATCH] bool function and while loop to compare answers --- src/main/quizproject.c | 29 +++++++++++++++++++++++++++-- src/main/quizproject.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/quizproject.c b/src/main/quizproject.c index 495aaa8..dfce924 100644 --- a/src/main/quizproject.c +++ b/src/main/quizproject.c @@ -56,7 +56,15 @@ void e_t_f_printQuestions(char askquestion[][100],char answers[]) { printf("[%d]. %s", i + 1, askquestion[i]); scanf(" %c", &user_answer); user_answer = toupper(user_answer); - printf(" The answer is: %d\n\n", answers[i]); + while (user_answer != 'T' || user_answer != 'F' ){ + if(user_answer == 'T' || user_answer == 'F') { + break; + } else { + printf("Input is invalid! Enter 'T' for true or 'F' for false [T/F]:\n"); + scanf(" %c", &user_answer); + user_answer = toupper(user_answer); + } + } } printf("\t\t---------------------------Round2-----------------------------\n"); printf("\t\t >>In this round you will be presented with 2 questions.<<\n"); @@ -65,7 +73,15 @@ void e_t_f_printQuestions(char askquestion[][100],char answers[]) { printf("[%d]. %s", i + 1, askquestion[i]); scanf(" %c", &user_answer); user_answer = toupper(user_answer); - printf(" The answer is: %d\n\n", answers[i]); + while (user_answer != 'T' || user_answer != 'F' ){ + if(user_answer == 'T' || user_answer == 'F') { + break; + } else { + printf("Input is invalid! Enter 'T' for true or 'F' for false [T/F]:\n"); + scanf(" %c", &user_answer); + user_answer = toupper(user_answer); + } + } } } @@ -94,6 +110,15 @@ void e_ask_questions(void) { e_t_f_printQuestions(e_t_f_question, e_t_f_solution); } +bool e_true_false(char choice) { + if (choice == 'T') { + return true; + } else if(choice == 'F') { + return false; + } else { + return -1; + } +}; void e_smart_brain() { e_display_instruction(); diff --git a/src/main/quizproject.h b/src/main/quizproject.h index 86e854a..7428fa5 100644 --- a/src/main/quizproject.h +++ b/src/main/quizproject.h @@ -37,6 +37,7 @@ void e_display_instruction(void); void e_t_f_printQuestions(char [][100],char []); void e_ask_questions(void); void e_smart_brain(void); +bool e_true_false(char); //----smart_brain_header_end-------