Kodewick
学びはじめる →
基礎←→0 / 60

ボウリングの夜

#037基礎int &low, int &high約 5 分

ボウリングで何ゲームか遊び、scores に各ゲームの点数が入っています(1 つ以上あります)。low_high は最低点と最高点を 2 つの参照 low と high で返します。ループの中を書きましょう。より低ければ low を、より高ければ high を置き換えます。

例
score_range({120, 98, 145, 110})→'98 ~ 145'
score_range({77})→'77 ~ 77'
関数string 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) {
        // ここにコードを書く:低ければ low を、高ければ 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 でも実行できます
結果

実行すると例で試せます。よさそうなら提出しましょう。