From 0f394a2fa63eadfd7a80673e138b53cdcdfecfb9 Mon Sep 17 00:00:00 2001 From: fdlt3914 Date: Mon, 6 Feb 2023 13:47:32 +0000 Subject: [PATCH] Math quiz:display of questions and choice --- src/main/quizproject.c | 50 +++++++++++++++++++++++++++++++++++++++++- src/main/quizproject.h | 11 ++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/main/quizproject.c b/src/main/quizproject.c index d41cd44..427f5f7 100644 --- a/src/main/quizproject.c +++ b/src/main/quizproject.c @@ -28,6 +28,49 @@ int* randomNumber() { } +//------------Math_quiz_begin------------ + +void math_choose_question(int num) { + char choose [][100] = { + "what is 1 + 1\n", + "what is 4 + 3\n", + "what is 4 * 8\n", + "what is ((6*8)/4)+2\n" + }; + printf("%s", choose[num]); +} + +int math_answer(int num1) { + int ans[]= { + 2, + 7, + 32, + 14 + }; + return ans[num1]; +} + +void math_display_choice(){ + int user_answer; + for(int i = 0; i < 4; i++){ + math_choose_question(i); + printf("Answer: "); + scanf("%d", &user_answer); + int quiz_answer = math_answer(i); + if(quiz_answer == user_answer){ + printf("Correct!\n"); + } else { + printf("Wrong!\n"); + } + } + +} + +//------------Math_quiz_end-------------- + + + + //-------smart_brain_quiz_begin---------- void e_press_key_start() { @@ -1977,7 +2020,8 @@ int main(int argc, char *argv[]) { printf("6. Smart Brain\n"); printf("7. Epic Game\n"); printf("8. Rock,Paper,Scissors!\n"); - printf("9. Exit\n"); + printf("9. Math Quiz\n"); + printf("10. Exit\n"); printf("Enter your choice: "); scanf("%d", &choice); v_progress_bar(argc,argv); @@ -2016,6 +2060,10 @@ int main(int argc, char *argv[]) { jump_to_menu = 1; break; case 9: + math_display_choice(); + jump_to_menu = 1; + break; + case 10: printf("\nThank you for trying our C code!\n"); break; default: diff --git a/src/main/quizproject.h b/src/main/quizproject.h index 70eea77..b1653f7 100644 --- a/src/main/quizproject.h +++ b/src/main/quizproject.h @@ -36,6 +36,17 @@ void million_instructions(); void million_exit(int million_a); +//------Math_quiz_header_begin----- + +void math_choose_question(int); +int math_answer(int); +void math_display_choice(); + +//------Math_quiz_header_end------- + + + + //----smart_brain_header_begin----- void e_press_key_start(void);