C++ Write a program that calculates the total grade for N classroom exercises as
ID: 660583 • Letter: C
Question
C++
Write a program that calculates the total grade for N classroom exercises as a percentage. The user should input the value for N followed by each of the N scores and totals. Calculate the overall percentage (sum of the total points earned divided by the total points possible) and output it as a percentage. Sample input and output is shown below.
How many exercises to input? 3
Score received for exercise 1: 10
Total points possible for exercise 1: 10
Score received for exercise 2: 7
Total points possible for exercise 2: 12
Score received for exercise 3: 5
Total points possible for exercise 3: 8
Your total is 22 out of 30, or 73.33%.
Explanation / Answer
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int input;
cout <<"How many exercises to input? ";
cin >> input;
cout << endl;
int earned_sum =0;
int total_sum = 0;
for(int i=0; i<input; i++)
{
int score;
int total;
cout <<"Score received for exercise " << (i+1) <<" : ";
cin >> score;
cout << endl;
earned_sum = earned_sum + score;
cout <<"Total points possible for exercise " << (i+1) <<" : ";
cin >> total;
cout << endl;
total_sum = total_sum + total;
}
cout << "Your total is " << earned_sum << " out of " << total_sum << ", or " << setprecision(4)<< static_cast<double> (earned_sum*100)/static_cast<double> (total_sum) << "%." << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.