Write a C++ program to get 5 subjects marks of a student and then calculate its total, average and percentage and display them on the screen.
![]() |
Write a C++ program to get 5 subjects marks of a student and then calculate its total, average and percentage and display them on the screen. |
Sure, here's a C++ program that prompts the user to enter marks for 5 subjects, calculates the total, average, and percentage, and displays the results on the screen:
#include <iostream>
using namespace std;
int main() {
int marks[5], total = 0;
float avg, percent;
cout << "Enter marks of 5 subjects: " << endl;
// Get marks for each subject and calculate total
for(int i=0; i<5; i++) {
cout << "Subject " << i+1 << ": ";
cin >> marks[i];
total += marks[i];
}
// Calculate average and percentage
avg = total / 5.0;
percent = (total / 500.0) * 100;
// Display results
cout << "Total marks: " << total << endl;
cout << "Average marks: " << avg << endl;
cout << "Percentage: " << percent << "%" << endl;
return 0;
}
Here's an example of how the program could be used:
Enter marks of 5 subjects:
Subject 1: 85
Subject 2: 78
Subject 3: 92
Subject 4: 88
Subject 5: 90
Total marks: 433
Average marks: 86.6
Percentage: 86.6%
0 Comments