1.Marks statistics
BeginnerGiven std::vector<int> marks = {56, 91, 78, 34, 88};, print the total, the average (as a decimal) and the highest mark.
Show hint
One range-based for loop can add up the total and track the highest value at the same time.
Show solution
#include <iostream>
#include <vector>
int main() {
std::vector<int> marks = {56, 91, 78, 34, 88};
int total = 0;
int highest = marks[0];
for (int m : marks) {
total += m;
if (m > highest) highest = m;
}
std::cout << "Total: " << total << '\n';
std::cout << "Average: " << static_cast<double>(total) / marks.size() << '\n';
std::cout << "Highest: " << highest << '\n';
}Total: 347
Average: 69.4
Highest: 91