Browse Source

use switch statement to select question of choice.

main
parent
commit
f650bab8f0
  1. 26
      src/main/quizproject.c

26
src/main/quizproject.c

@ -51,17 +51,29 @@ int math_answer(int num1) {
} }
void math_display_choice(){ 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){
int user_answer, ques_ans;
while (ques_ans != 4) {
printf("Choose a number between 1 and 4: ");
scanf("%d", &user_answer);
user_answer = user_answer-1;
switch(user_answer){
case 0: case 1: case 2: case 3:
math_choose_question(user_answer);
printf("Answer: ");
scanf("%d", &ques_ans);
break;
default:
printf("Invalid choice!\n");
break;
}
int quiz_answer = math_answer(user_answer);
if(quiz_answer == ques_ans){
printf("Correct!\n"); printf("Correct!\n");
} else { } else {
printf("Wrong!\n"); printf("Wrong!\n");
break;
} }
} }
} }

Loading…
Cancel
Save