Café customers give 1 to 5 stars each. Write one line: use accumulate to add up stars into total. The average is whole-number division, so the fraction is dropped; with no ratings it returns 0 (already in the starter).
average_stars({5, 4, 4})→4average_stars({})→0int average_stars(const vector<int> &stars)#include <numeric>
#include <vector>
using namespace std;
int average_stars(const vector<int> &stars) {
if (stars.empty()) {
return 0;
}
int total = 0;
// your code here: work out total with accumulate
return total / stars.size();
}
Run tries the examples. When they look right, Submit.