Answer to Question #47675 in C++ for Luqman Ahmed
Write a program to calculate total marks and percentage of three subjects?
1
2014-10-09T09:37:52-0400
Code
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int mark1;
int mark2;
int mark3;
float pMark1;
float pMark2;
float pMark3;
int total;
// Input
cout << "Subject 1 mark: ";
cin >> mark1;
cout << "Subject 2 mark: ";
cin >> mark2;
cout << "Subject 3 mark: ";
cin >> mark3;
// Total mark
total = mark1 + mark2 + mark3;
// Percentage
pMark1 = ((float) mark1 /(float) total) * 100;
pMark2 = ((float) mark2 /(float) total) * 100;
pMark3 = ((float) mark3 /(float) total) * 100;
// Output
cout << "Total mark: " << total << endl;
cout << "Subject 1 percentage: " << fixed << setprecision(2) << pMark1 << "%" << endl;
cout << "Subject 2 percentage: " << fixed << setprecision(2) << pMark2 << "%" << endl;
cout << "Subject 3 percentage: " << fixed << setprecision(2) << pMark3 << "%";
return 0;
}
Result
Subject 1 mark: 12
Subject 2 mark: 21
Subject 3 mark: 33
Total mark: 66
Subject 1 percentage: 18.18%
Subject 2 percentage: 31.82%
Subject 3 percentage: 50.00%
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!
Learn more about our help with Assignments:
C++
Comments
Leave a comment