Kodewick
Start learning →
Basic←→0 / 60

Marking the quiz

#038BasicReferencesLoops4 min

The teacher is marking a quiz: in answers, true is a right answer and false a wrong one. mark hands back how many were right and wrong through two references, right and wrong. Fill in the loop. With no questions, both are 0.

Examples
quiz_result({true, true, false, true})→'3 right, 1 wrong'
quiz_result({})→'0 right, 0 wrong'
The functionstring quiz_result(const vector<bool> &answers)
main.cpp
#include <string>
#include <vector>
using namespace std;

void mark(const vector<bool> &answers, int &right, int &wrong) {
    right = 0;
    wrong = 0;
    for (bool ok : answers) {
        // your code here: add 1 to right or to wrong
    }
}

string quiz_result(const vector<bool> &answers) {
    int right = 0, wrong = 0;
    mark(answers, right, wrong);
    return to_string(right) + " right, " + to_string(wrong) + " wrong";
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.