From 5fb7927aa34816bcd9761e668dba38a4369c77f4 Mon Sep 17 00:00:00 2001 From: fdlt3914 Date: Fri, 10 Feb 2023 04:28:37 +0000 Subject: [PATCH] refactoring: proper renaming in math_display_choice --- src/main/quizproject.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/quizproject.c b/src/main/quizproject.c index ddd7292..6270889 100644 --- a/src/main/quizproject.c +++ b/src/main/quizproject.c @@ -190,36 +190,36 @@ int math_answer(int num1) { } void math_display_choice(){ - int user_answer, ques_ans,repeat = 0; + int user_choice, user_answer,repeat = true; printf("Choose a number between 1 and 4(game ends with invalid number or wrong answer): "); - scanf("%d", &user_answer); - user_answer = user_answer-1; - int quiz_answer = math_answer(user_answer); - while (user_answer != 4 || repeat) { - quiz_answer = math_answer(user_answer); - switch(user_answer){ + scanf("%d", &user_choice); + user_choice = user_choice-1; + int quiz_answer = math_answer(user_choice); + while (user_choice != 4 || repeat) { + quiz_answer = math_answer(user_choice); + switch(user_choice){ case 0: case 1: case 2: case 3: - math_choose_question(user_answer); + math_choose_question(user_choice); printf("Answer: "); - scanf("%d", &ques_ans); - repeat =1; + scanf("%d", &user_answer); + repeat =false; break; default: printf("Invalid choice!\n"); } - if(quiz_answer == ques_ans){ + if(quiz_answer == user_answer){ printf("Correct!\n"); } else { printf("Wrong!\n"); break; } - if (repeat) { - repeat = 0; + if (!(repeat)) { + repeat = true; printf("Choose a number between 1 and 4(game ends with invalid number or wrong answer): "); - scanf("%d", &user_answer); - user_answer = user_answer-1; + scanf("%d", &user_choice); + user_choice = user_choice-1; } } @@ -887,9 +887,9 @@ void math_question2(){ void compare_answer(char compare, char character1){ if (compare == character1) { score++; - printf("Right!, score is: %d\n", score); + correct(score); } else { - printf("Wrong! score is: %d\n", score); + wrong(score); } }