diff --git a/src/main/quizproject.c b/src/main/quizproject.c index 5715950..3f056e9 100644 --- a/src/main/quizproject.c +++ b/src/main/quizproject.c @@ -46,15 +46,13 @@ 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; 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]); - scanf(" %c", &user_answer); + for(i = initial; i < end; i++) { + printf("[%d]. %s", i + 1, question[i]); + scanf(" %c", &user_answer); user_answer = toupper(user_answer); while (user_answer != 'T' || user_answer != 'F' ){ if(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); } } - bool ans = e_true_false(user_answer); - if(ans == answers[i]) { + bool ans1 = e_true_false(user_answer); + if(ans1 == ans[i]) { score++; - printf("Correct!\n"); - printf("You have %d score\n\n", score); + correct(score); } 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 >>In this round you will be presented with 2 questions.<<\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) { diff --git a/src/main/quizproject.h b/src/main/quizproject.h index 7428fa5..625e0d0 100644 --- a/src/main/quizproject.h +++ b/src/main/quizproject.h @@ -38,6 +38,7 @@ void e_t_f_printQuestions(char [][100],char []); void e_ask_questions(void); void e_smart_brain(void); bool e_true_false(char); +void e_usr_answr(char [][100], char [], int, int); //----smart_brain_header_end-------