Write a program that calculates the total grade for N classroom exercises as a p
ID: 3774264 • Letter: W
Question
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
Please follow the code and comments for description :
CODE :
#include <iostream> // required header files
#include <iomanip>
using namespace std;
int main() // driver method
{
int exerCount, score, possiblePts, total = 0, reqTotal = 0; // local variables
double percent;
cout << "How many Exercises to input ? : "; // prompt for the user
cin >> exerCount; // get the value
for(int i = 0; i < exerCount; i++) { // iterate over the count
cout << " Score received for exercise " << (i + 1) << " : "; // get the result and data
cin >> score;
total = total + score; // update the total
cout << "Total Points Possible for exercise " << (i + 1) << " : ";
cin >> possiblePts;
reqTotal = reqTotal + possiblePts; // update the value
}
percent = ((double)total/reqTotal) * 100; // get the percentage
cout << " Your Total is " << total << " out of " << reqTotal << ", or " << setprecision(4) << percent << "%." << endl; // print the data to console
}
OUTPUT :
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%.
Hope this is helpful.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.