Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string name;
- cin >> name;
- int failedExams = 0;
- int completedClass = 0;
- double sumGrades = 0, grade;
- while (completedClass < 12 && failedExams < 2) {
- cin >> grade;
- if (grade >= 4) {
- sumGrades += grade;
- completedClass++;
- }
- else {
- failedExams++;
- }
- }
- if (completedClass == 12) {
- printf("%s graduated. Average grade: %.2f\n", name.c_str(), sumGrades / 12);
- }
- else {
- printf("%s has been excluded at %i grade", name.c_str(), completedClass + 1);
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string name;
- cin >> name;
- int failedExams = 0;
- int completedClass = 0;
- double sumGrades = 0, grade;
- while (completedClass < 12 && failedExams < 2) {
- cin >> grade;
- sumGrades += grade >= 4 ? grade : 0;
- grade >= 4 ? completedClass++ : failedExams++;
- }
- completedClass == 12 ?
- printf("%s graduated. Average grade: %.2f\n", name.c_str(), sumGrades / 12) :
- printf("%s has been excluded at %i grade", name.c_str(), completedClass + 1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement