Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int badGrades;
- cin >> badGrades;
- cin.ignore();
- string task, lastProblem;
- getline(cin, task);
- int badGradesCounter = 0, tasksCount = 0;
- double gradesTotal = 0, grade;
- while (task != "Enough") {
- cin >> grade;
- cin.ignore();
- gradesTotal += grade;
- tasksCount++;
- if (grade <= 4) {
- badGradesCounter++;
- if (badGradesCounter == badGrades) {
- printf("You need a break, %i poor grades.\n", badGradesCounter);
- break;
- }
- }
- lastProblem = task;
- getline(cin, task);
- }
- if (task == "Enough") {
- printf("Average score: %.2f\n", gradesTotal / tasksCount);
- printf("Number of problems: %i\n", tasksCount);
- printf("Last problem: %s\n", lastProblem.c_str());
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int badGrades;
- cin >> badGrades;
- cin.ignore();
- string task, lastProblem;
- getline(cin, task);
- int badGradesCounter = 0, tasksCount = 0;
- double gradesTotal = 0, grade;
- while (task != "Enough" && badGradesCounter != badGrades) {
- cin >> grade;
- cin.ignore();
- gradesTotal += grade;
- tasksCount++;
- if (grade <= 4) {
- badGradesCounter++;
- }
- lastProblem = task;
- getline(cin, task);
- }
- task == "Enough" ?
- printf("Average score: %.2f\nNumber of problems: %i\nLast problem: %s\n", gradesTotal / tasksCount, tasksCount, lastProblem.c_str()) :
- printf("You need a break, %i poor grades.\n", badGradesCounter);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement