Question #47675

Write a program to calculate total marks and percentage of three subjects?

Expert's answer

#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;

}

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%

## Comments

## Leave a comment