Browse Source

refactoring: simplification of question output

main
parent
commit
44b14e6afe
  1. 57
      src/main/quizproject.c
  2. 1
      src/main/quizproject.h

57
src/main/quizproject.c

@ -46,14 +46,12 @@ void e_display_instruction() {
} }
void e_t_f_printQuestions(char askquestion[][100],char answers[]) {
void e_usr_answr(char question[][100], char ans[], int initial, int end){
int i; int i;
char user_answer; char user_answer;
printf("\t\t---------------------------Round1-----------------------------\n");
printf("\t\t >>In this round you will be presented with 3 questions.<<\n");
printf("\t\t--------------------------------------------------------------\n\n");
for(i = 0; i < 3; i++) {
printf("[%d]. %s", i + 1, askquestion[i]);
for(i = initial; i < end; i++) {
printf("[%d]. %s", i + 1, question[i]);
scanf(" %c", &user_answer); scanf(" %c", &user_answer);
user_answer = toupper(user_answer); user_answer = toupper(user_answer);
while (user_answer != 'T' || user_answer != 'F' ){ while (user_answer != 'T' || user_answer != 'F' ){
@ -65,42 +63,31 @@ void e_t_f_printQuestions(char askquestion[][100],char answers[]) {
user_answer = toupper(user_answer); user_answer = toupper(user_answer);
} }
} }
bool ans = e_true_false(user_answer);
if(ans == answers[i]) {
bool ans1 = e_true_false(user_answer);
if(ans1 == ans[i]) {
score++; score++;
printf("Correct!\n");
printf("You have %d score\n\n", score);
correct(score);
} else{ } else{
printf("Wrong!\n");
printf("You have %d score\n\n", score);
wrong(score);
}
} }
} }
void e_t_f_printQuestions(char askquestion[][100],char answers[]) {
printf("\t\t---------------------------Round1-----------------------------\n");
printf("\t\t >>In this round you will be presented with 3 questions.<<\n");
printf("\t\t--------------------------------------------------------------\n\n");
int init = 0, end = 3;
e_usr_answr(askquestion,answers, init, end);
printf("\t\t---------------------------Round2-----------------------------\n"); printf("\t\t---------------------------Round2-----------------------------\n");
printf("\t\t >>In this round you will be presented with 2 questions.<<\n"); printf("\t\t >>In this round you will be presented with 2 questions.<<\n");
printf("\t\t--------------------------------------------------------------\n\n"); printf("\t\t--------------------------------------------------------------\n\n");
for(i = 3; i < 5; i++) {
printf("[%d]. %s", i + 1, askquestion[i]);
scanf(" %c", &user_answer);
user_answer = toupper(user_answer);
while (user_answer != 'T' || user_answer != 'F' ){
if(user_answer == 'T' || user_answer == 'F') {
break;
} else {
printf("Input is invalid! Enter 'T' for true or 'F' for false [T/F]:\n");
scanf(" %c", &user_answer);
user_answer = toupper(user_answer);
}
}
bool ans = e_true_false(user_answer);
if(ans == answers[i]) {
score++;
printf("Correct!\n");
printf("You have %d score\n\n", score);
} else{
printf("Wrong!\n");
printf("You have %d score\n\n", score);
}
}
init = 3, end = 5;
e_usr_answr(askquestion,answers, init, end);
} }
void e_ask_questions(void) { void e_ask_questions(void) {

1
src/main/quizproject.h

@ -38,6 +38,7 @@ void e_t_f_printQuestions(char [][100],char []);
void e_ask_questions(void); void e_ask_questions(void);
void e_smart_brain(void); void e_smart_brain(void);
bool e_true_false(char); bool e_true_false(char);
void e_usr_answr(char [][100], char [], int, int);
//----smart_brain_header_end------- //----smart_brain_header_end-------

Loading…
Cancel
Save