Dec 29, 2011

Using else if statement

Using else if statement

Else if statement is similar to if condition. In else-if condition you can give more than one condition like we have to give grade if students score greater than 90 got A grade, b/w 70-90 got B grade , 50-70 got C grade and so on. it require more than one condition. So we use else if condition check out example for better understand.




#include<iostream.h>
#include<conio.h>
int main()

int eng,sc,maths;
float percentage;
cout << "Enter Marks of student in\n";
cout << "In english \n";
cin>> eng;
cout << "In Science\n";
cin>>sc;
cout <<"In maths\n";
cin >> maths;
percentage = (sc+maths+eng)/3; // %age formula (total / 300) * 100

if(percentage > 90) // check condition
{
cout << "A Grade\n";
}
else if(percentage > 70)//similar to if also check condition
{
cout << "B Grade\n";
}
else if(percentage > 50)
{
cout<< " C Grade\n";
}
else if(percentage > 40)
{
cout << "D Grade\n";
}
else 
{
cout << "E Grade\n";
}
getch();
return 0;
}

OUTPUT



0 comments:

Post a Comment