+ 1

my if else statement doesnt work

``` int mark; cout << "whats your grade?"; cin >> mark; if (mark >= 5) { cout << "you passed"; if (mark == 10){ cout << "perfect!"; } } else { cout << "you failed"; } ``` why doesnt it work? i mean it doesnt work when you type in "10"

20th Apr 2020, 9:58 PM
Alexandru Serban
Alexandru Serban - avatar
1 Answer
0
according to your code if >=5 make print rhen if == 10 make print. last else is opoaite of >=5. so if you enter 10 is more 5 so print, then second print since 10==10. in your case if you want to get only 1 print there are 2 ways if eq 10{perfect} else if >=5{pass} else {fail} or. if >=5 { if == 10 {perfect} else {passes} } else{ failed}
20th Apr 2020, 10:40 PM
george
george - avatar