Answer to Question #322755 in C++ for nickname

Question #322755

This program will calculate the average(%) of exam grades.

It will also add extra credit points to the exam average given the course difficulty.

Enter all of the grades for one student. Type (-1) when finished with that student.

If you have additional students, you will be prompted to repeat the program at the end.

 

Enter an exam grade (type -1 to quit):  user types: ten

Error: Grades must be an integer 0 or higher.

Enter an exam grade (type -1 to quit):  user types: 100

Enter an exam grade (type -1 to quit):  user types: 50

Enter an exam grade (type -1 to quit):  user types: -1

 

Exam average, including extra credit, is: 78

The equivalent letter grade is: C

Would you like to enter grades for another student (Y or N)?  user types: N


1
Expert's answer
2022-04-03T07:59:46-0400
#include <iostream>
#include <cctype>
using namespace std;


int main() {
    char ans = 'Y';

    while (ans == 'Y') {
        int total = 0;
        int n = 0;
        int grade = 0;


        while (grade >= 0) {
            cout << "Enter an exam grade (type -1 to quit): ";
            cin >> grade;
            if (!cin.fail() && grade >= 0) {
                n++;
                total += grade;
            }
            else {
                cout << "Error: Grades must be an integer 0 or higher." << endl;
                cin.clear();
                cin.ignore(numeric_limits<streamsize>::max(), '\n');
            }
        }
        char letter;
        int avg = total / n + 3;
        if (avg >= 90) {
            letter = 'A';
        }
        else if (avg >= 80) {
            letter = 'B';
        }
        else if (avg >= 70) {
            letter = 'C';
        }
        else if (avg >= 60) {
            letter = 'C';
        }
        else {
            letter = 'F';
        }
        cout << "Exam average, including extra credit, is: " << avg << endl;
        cout << "The equivalent letter grade is: " << letter << endl;

        cout << "Would you like to enter grades for another student (Y or N)? ";
        cin >> ans;
        ans = toupper(ans);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS