Kodewick
Start learning →
Basic←→0 / 60

Bowling night

#037BasicReferencesvector5 min

Bowling night had several games, and scores holds each game's score; there is at least one. low_high hands back the lowest and highest through two references, low and high. Fill in the loop: anything lower replaces low, anything higher replaces high.

Examples
score_range({120, 98, 145, 110})→'98 ~ 145'
score_range({77})→'77 ~ 77'
The functionstring score_range(const vector<int> &scores)
main.cpp
#include <string>
#include <vector>
using namespace std;

void low_high(const vector<int> &scores, int &low, int &high) {
    low = scores[0];
    high = scores[0];
    for (int s : scores) {
        // your code here: lower replaces low, higher replaces high
    }
}

string score_range(const vector<int> &scores) {
    int low = 0, high = 0;
    low_high(scores, low, high);
    return to_string(low) + " ~ " + to_string(high);
}
Ctrl + Enter runs too
Result

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