Write a C++ Program to Calculate Student Marks with example. The below shown C++ program allows entering five different subjects marks. Next, it calculates the total, average, and percentage of those five subjects and prints the result.
#include<iostream>
using namespace std;
int main()
{
int english, chemistry, computers, physics, maths;
float total, average, percentage;
cout << "Please Enter the marks of five subjects: \n";
cin >> english >> chemistry >> computers >> physics >> maths;
total = english + chemistry + computers + physics + maths;
average = total / 5;
percentage = (total / (500)) * 100;
cout << "\nTotal Marks = " << total;
cout << "\nAverage Marks = " << average;
cout << "\nMarks Percentage = " << percentage;
return 0;
}
C++ Program to Calculate Student Marks Example 2
This C++ program allows the user to choose the total number of student subjects. Next, it calculated the student marks.
#include<iostream>
using namespace std;
int main()
{
int totalSubjects;
float marks, total = 0, average, percentage;
cout << "Please Enter the Total Number of subjects = ";
cin >> totalSubjects;
cout << "Please Enter the Marks for each subjects = ";
for(int i = 0; i < totalSubjects; i++)
{
cin >> marks;
total = total + marks;
}
average = total / totalSubjects;
percentage = (total / (totalSubjects * 100)) * 100;
cout << "\nTotal Marks = " << total;
cout << "\nAverage Marks = " << average;
cout << "\nMarks Percentage = " << percentage;
return 0;
}