Browse Source

refactoring: proper renaming in math_display_choice

main
parent
commit
5fb7927aa3
  1. 34
      src/main/quizproject.c

34
src/main/quizproject.c

@ -190,36 +190,36 @@ int math_answer(int num1) {
} }
void math_display_choice(){ 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): "); 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: case 0: case 1: case 2: case 3:
math_choose_question(user_answer);
math_choose_question(user_choice);
printf("Answer: "); printf("Answer: ");
scanf("%d", &ques_ans);
repeat =1;
scanf("%d", &user_answer);
repeat =false;
break; break;
default: default:
printf("Invalid choice!\n"); printf("Invalid choice!\n");
} }
if(quiz_answer == ques_ans){
if(quiz_answer == user_answer){
printf("Correct!\n"); printf("Correct!\n");
} else { } else {
printf("Wrong!\n"); printf("Wrong!\n");
break; 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): "); 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){ void compare_answer(char compare, char character1){
if (compare == character1) { if (compare == character1) {
score++; score++;
printf("Right!, score is: %d\n", score);
correct(score);
} else { } else {
printf("Wrong! score is: %d\n", score);
wrong(score);
} }
} }

Loading…
Cancel
Save