C++
Write a program that calculates and prints the total grade for n
assignments
as a percentage. Prompt the user to enter the value of n, followed
by the number
of points received and number of points possible for each
assignment . Calculate
and print the total number of points received, total number of
points possible,
and the overall percentage: (total points received / total points
possible) * 100.
Output:
Enter·number·of·assignments·to·input:3↵
Enter·number·of·points·received·for·assignment·1 :10↵
Enter·number·of·possible·points·for·assignment·1 :10↵
Enter·number·of·points·received·for·assignment·2 :7↵
Enter·number·of·possible·points·for·assignment·2 :12↵
Enter·number·of·points·received·for·assignment·3 :5↵
Enter·number·of·possible·points·for·assignment·3 :8↵
our·total·amount·of·points·is·22·out·of·30,·or·73.33%.↵
Program:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n;
int totalPointsReceived=0,
totalPointsPossible=0;
double overallPercentage;
int pointsReceived,pointsPossible;
//prompt and read the number of assignments
cout<<"\nEnter number of assignments to input:
";
cin>>n;
//run a loop to read n number of point
for(int i=0;i<n;i++)
{
//prompt and read points
received
cout<<"\nEnter number of
points received for assignment "<<(i+1)<<" : ";
cin>>pointsReceived;
//prompt and read points
possible
cout<<"\nEnter number of
possible points for assignment "<<(i+1)<<" : ";
cin>>pointsPossible;
//add the points to
totalPointsReceived
totalPointsReceived=totalPointsReceived+pointsReceived;
//add the points to
totalPointsPossible
totalPointsPossible=totalPointsPossible+pointsPossible;
}
//calculate the overall percentage
overallPercentage = ((double)totalPointsReceived /
(double)totalPointsPossible) * 100.00;
//print the output
cout<<"\nOur total amount of points is
"<<totalPointsReceived<<" out of
"<<totalPointsPossible<<" or
"<<setprecision(4)<<overallPercentage<<"%";
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.