Answer to Question #263841 in C for Jack

Question #263841

You are requested to write a program which will be used to take the entry test for university


students. The program must have following features.


• For correct answer, students get 4 marks.


• For wrong answer, student lose 1 mark.


• If the student answers first four questions wrong exit the program with a message “Sorry,


you did not qualify for the admission.”


• If students score 20 marks, program should display “Congratulations, you have qualified for


the admission “and exit.


• There will be only 4 options for each question

1
Expert's answer
2021-11-10T06:34:26-0500
#include <stdio.h>
#define N_TEST 10

int main() {
    int correct_aswers[N_TEST] = { 1, 2, 3, 3, 2, 1, 1, 2, 3, 4 };
    int ans;
    int tot_marks = 0;
    
    int i = 0;

    while (1) {
        printf("Get answer on the question %d (1 - 4): ", i+1);
        scanf("%d", &ans);
        if ( ans < 1 || ans > 4) {
            printf("Uncorrect answer\n\n");
            continue;
        }
        if (ans == correct_aswers[i]) {
            tot_marks += 4;
        }
        else {
            tot_marks--;
        }
        if (tot_marks == -4) {
            printf("Sorry, you did not qualify for the admission.\n");
            break;
        }
        if (tot_marks >= 20) { 
            printf("Congratulations, you have qualified for the admission\n");
            break;
        }
        i++;
        if ( i == N_TEST) {
            i = 0;
        }
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS