Wednesday, 16 April 2014

Nested If Statement+Logic Gates- Using C++

//Question is:
/*if gender is male and grade is 70 and above,display "goodboy";
if gender is female and grade is 70 above, display "goodgirl";
but if grade is below 70 regardless of gender,display "badchild";  */

//Source Code:

#include<iostream>
using namespace std;
main()
{
int grade;
char gender;

cout<<"Gender Is:";
cin>>gender;
cout<<"Grade Is:";
cin>>grade;

if(gender =='M'||'m')
if(grade>=70)
cout<<"goodboy";

if(gender=='F'||'f')
if(grade>=70)
cout<<"\n goodgirl";

else
cout<<"\n badchild";

return 0;
}

Output:


No comments:

Post a Comment