ボウリングで何ゲームか遊び、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)#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);
}
実行すると例で試せます。よさそうなら提出しましょう。