Answer to Question #240020 in C++ for qwerty

Question #240020

Create a quiz answer sheet checker. That does the following: 1. Posts questions – at least 5- then let the user input answers per question , it can be a multiple choice question, or solving question which will have a number for an answer. 2. After the user inputs their answer, let the program check the answer and display the score of the user.


1
Expert's answer
2021-09-22T00:05:37-0400
#include <iostream>
#include <string>
#include <cstdio>
#include <Windows.h>


using namespace std;


int main() {
    cout << "1. The first question\n" << //write yor questions here
        "2. The second question\n" <<
        "3. The third question\n" <<
        "4. The fourth question\n" <<
        "5. The fifth question\n\n";
    short int number_of_questions = 5;
    short int score = 0;
    string ans;


    for (int i = 0; i < number_of_questions; i++) {
        cout << "Enter the number of the answering question: ";
        int n;
        cin >> n;
        switch (n) {
        case 1:
            cout << "Enter the answer: ";
            getline(cin, ans);
            getline(cin, ans);
            
            if (ans == "answer 1") { //write yor correst answers here
                cout << "Your score is: " << ++score << endl;
            }


            break;
        case 2:
            cout << "Enter the answer: ";
            getline(cin, ans);
            getline(cin, ans);


            if (ans == "answer 2") {
                cout << "Your score is: " << ++score << endl;
            }


            break;
        case 3:
            cout << "Enter the answer: ";
            getline(cin, ans);
            getline(cin, ans);


            if (ans == "answer 3") {
                cout << "Your score is: " << ++score << endl;
            }


            break;
        case 4:
            cout << "Enter the answer: ";
            getline(cin, ans);
            getline(cin, ans);


            if (ans == "answer 4") {
                cout << "Your score is: " << ++score << endl;
            }


            break;
        case 5:
            cout << "Enter the answer: ";
            getline(cin, ans);
            getline(cin, ans);


            if (ans == "answer 5") {
                cout << "Your score is: " << ++score << endl;
            }


            break;
        default:
            cout << "wrong answer" << endl;
            break;
        }
    }
    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