In this program, we calculate the grade and percentage of a student according to 6 subjects marks by the given below methods by if-else loop concepts basic to advance loop in c++
best if else if loop example with explanation
The method of assigning grades is –
percentage>=85 grade=A
percentage<85 and percentage>=70 grade=B
percentage<70 and percentage>=55 grade=C
percentage<55 and percentage>=40 grade=D
percentage<40 grade=E
using namespace std;
int main()
{
float m1,m2,m3,m4,m5,m6,total,per;
//Makeing all marks Float type variables
char grade;
//Makeing a char type for grade
cout <<“Please enter S1 marks of Subject 1 :”<
cout<<“Please enter S1 marks of Subject 2 :\t ” <
cout<<“Please enter S1 marks of Subject 3 :\t “<< endl;
cin>>m3;
cout<<“Please enter S1 marks of Subject 4 :\t “<< endl;
cin>>m4;
cout<<“Please enter S1 marks of Subject 5 :\t “<< endl;
cin>>m5;
cout<<“Please enter S1 marks of Subject 6 :\t “<< endl;
cin>>m6;
//Calculate the percentage of all Marks
total=m1+m2+m3+m4+m5+m6;
per=total/6;
//Condtion Check for to find the grade of
if(per>33){
if(per>=85){
grade=’A’;
}
else if(per>=70){
grade=’B’;
}
else if(per>=55){
grade=’C’;
}
else if(per>=40){
grade=’D’;
}
else {
grade=’E’;
}
cout<<“Student S1 passed with ” << grade << ” Grade with ” <
else{
cout<<“Students S1 is Fail in the Examnation”<
return 0;
}
Suppose Student S1 find the folloing marks:
Subject 1=71, Subject 2 =72, Subject 3 = 73,
Subject 4 = 74, Subject 5 = 75, Subject 6 = 76,
output:
71
Please enter S1 marks of Subject 2 :
72
Please enter S1 marks of Subject 3 :
73
Please enter S1 marks of Subject 4 :
74
Please enter S1 marks of Subject 5 :
75
Please enter S1 marks of Subject 6 :
76
Student S1 passed with B Grade with 73.5Process returned 0 (0x0) execution time : 14.507 s
Press any key to continue.
I make this programming and hope you are like the post if are you like the post you can please comment and share the post to reach more people.
If any doubt about this c++ programming code or input & output please comment below
If you have another question about c++ programming send an email by contacting us form is given on the page right side.
Share your experience about this post,
Thank You!