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";
PROBLEM:
The only problem is for example
for gender , i put F
for grade , i put 90
goodboy and goodgirl ,
both appears on my output .
i dont have any problem in badchild .
again, for example
gender:M
grade:75
goodboy
goodgirl
thats how it looks like .
instead of goodboy only , the goodgirl apeears also.
The problem with your code is that after if(gender=='M'||'m'), if(grade>=70) disregards the previous. The same way with if(gender=='F'||'f'), if(grade>=70) disregards the previous conditional statement. Thus, as long as the grade>=70 is met, it prints both.
you can have this code:
-----
1 2 3 4 5 6 7 8
if (grade < 70)
cout<<"\n badchild";
else {
if (gender == 'm' || gender == 'M')
cout<<"goodboy";
else
cout<<"goodgirl";
}
-------
or this code:
1 2 3 4 5 6 7 8 9 10 11 12
if (gender == 'm' || gender == 'M') {
if (grade < 70)
cout<<"\n badchild";
else
cout<<"goodboy";
}
else {
if (grade < 70)
cout<<"\n badchild";
else
cout<<"goodgirl";
}
-----------------
or have the if(gender=='F'||'f') first.
I would agree with jrfrago, but would like to add that in line 6 of his first example and line 10 of his second should be if (gender == 'F' || gender == 'f') as opposed to just an else. This is because if someone were to put any letter other than an M/m, it would return a "goodgirl" if their score was high enough.
You could have an initial if statement at the beginning that would test for valid input and continue to ask for the input until it receives it.