Odpowiedź :
Odpowiedź:
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
int main() {
std::vector<int> grades;
int grade;
int counter = 1;
while (grades.size() != 10) {
std::cout << "Podaj " << counter << " ocene\n";
std::cin >> grade;
if (grade < 2 || grade > 5) {
std::cout << "Podaj ocene z przedzialu <2-5>\n";
} else {
grades.push_back(grade);
counter++;
}
}
std::cout << "Wprowadzone oceny to:\n";
for (const auto &g: grades) {
std::cout << grade << std::endl;
}
int sum = std::accumulate(grades.begin(), grades.end(), 0);
std::cout << "Srednia ocen to: " << 1.0 * sum / 10 << std::endl;
int counterOf2 = std::count(grades.begin(), grades.end(), 2);
int counterOf5 = std::count(grades.begin(), grades.end(), 5);
std::cout << "Ocen ndst bylo " << counterOf2 << ", a bdb " << counterOf5;
return 0;
}
Wyjaśnienie: