Calculate total marks and percentage in C++
cin - Question 18
In this question, we will see how to input marks obtained in 5 different subjects in C++ programming using the cin statement and find out the total marks and percentage obtained. To know more about cin statement click on the cin statement lesson.
Q18) Write a program in C++ to input marks obtained in 5 different subjects and find out the total marks and percentage obtained by the student. Assume that the maximum mark in each subject is 100.
Program
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int e,m,h,g,c,total;
float per;
cout<<"English ";
cin>>e;
cout<<"Maths ";
cin>>m;
cout<<"History ";
cin>>h;
cout<<"Geography ";
cin>>g;
cout<<"Computer ";
cin>>c;
total=e+m+h+g+c;
per=(total/500.0)*100;
cout<<"Total Marks="<<total<<endl;
cout<<"Percentage="<<per;
return 0;
}
Output
English 75 Maths 62 History 84 Geography 77 Computer 91 Total Marks=389 Percentage=77.8