Input subject marks and check pass or fail in C++
if else if - Question 9
In this question, we will see how to input marks of English, Math and Computer of a student and check whether he is pass in the examination or not in C++ programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.
Q9) Write a program in C++ to input marks of English, Math and Computer of a student and check whether he is pass in the examination or not. For passing in an examination one must get above 40 in at least two subjects or the average of the three subjects must be greater than 40.
Program
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int s1,s2,s3;
float avg;
cout<<"Enter marks obtained in 3 subjects\n";
cin>>s1>>s2>>s3;
avg=(s1+s2+s3)/3.0;
if(s1>40 && s2>40)
{
cout<<"Pass";
}
else if(s2>40 && s3>40)
{
cout<<"Pass";
}
else if(s3>40 && s1>40)
{
cout<<"Pass";
}
else if(avg>40)
{
cout<<"Pass";
}
else
{
cout<<"Fail";
}
return 0;
}
Output
Enter marks obtained in 3 subjects 56 34 45 Pass