From 818c9764fc98128ee46dbd31e9fd97eaa667e2f1 Mon Sep 17 00:00:00 2001 From: fdlt3914 Date: Thu, 9 Feb 2023 23:12:45 +0000 Subject: [PATCH] brain_whiz comparing of answers --- src/main/quizproject.c | 36 ++++++++++++++++++++++++++++-------- src/main/quizproject.h | 3 ++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/quizproject.c b/src/main/quizproject.c index 1acdad0..bfb679e 100644 --- a/src/main/quizproject.c +++ b/src/main/quizproject.c @@ -778,22 +778,42 @@ void math_question2(){ "[A]. y = 7x - 1 [b]. y = 3x - 1 [c]. y = 3x + 3 [d]. y = 3x + 1", "[A]. x = -2 [b]. x = 3 [c]. x = 5 [d]. x = 11" }; - for_loop_print_question(math_question, math_possible_answer); + + char characters[] = { + 'A', + 'C', + 'B', + 'A', + 'D', + 'B', + 'C', + 'A', + 'D', + 'B' + }; + for_loop_print_question(math_question, math_possible_answer, characters); } +void compare_answer(char compare, char character1){ + int counter = 0; + if (compare == character1) { + counter++; + printf("Right!, score is: %d\n", counter++); + } else { + printf("Wrong!\n"); + } + +} -void for_loop_print_question(char mathQuestions[][140], char mathPossible[][140]) { - for (int i = 1; i < 5; i++){ +void for_loop_print_question(char mathQuestions[][140], char mathPossible[][140], char character[]) { + for (int i = 0; i < 5; i++){ char user_answer; printf("[%d]. %s",i, mathQuestions[i]); printf("%s", mathPossible[i]); scanf(" %c", &user_answer); - if (user_answer == 'A') { - printf("Right!\n"); - } else { - printf("Wrong!\n"); - } + char character0 = character[i]; + compare_answer(user_answer, character0); } } diff --git a/src/main/quizproject.h b/src/main/quizproject.h index 878d9ad..2fa8bb8 100644 --- a/src/main/quizproject.h +++ b/src/main/quizproject.h @@ -140,8 +140,9 @@ void b_historyevents(); //-------brain_whiz_header_begin------------ -void for_loop_print_question(char [][140], char [][140]); +void for_loop_print_question(char [][140], char [][140], char []); void math_question2(); +void compare_answer(char, char); //-------brain_whiz_header_end-------------