You are on page 1of 12

If ….

Else
Examples
What is the output of the following code?

Output: C
;int pay = 5, debt = 6, coll = 7, exp = 10
if (pay < coll)
if((debt > pay) && (coll >(debt – pay)))
;cout << coll
;else cout << debt
;else cout << exp

Output: 7
Consider the following segment of code. What
will appear on the screen if the user enters
?’‘f

;char genderCode
;" cout<<"Enter F for female or M for male
;cin>>genderCode
if(genderCode == 'F')
;cout<<"Female"<<endl
else
if(genderCode == 'M')
;cout<<"Male"<<endl
else
;cout<<"Invalid code"<<endl

Output: Invalid code

You might also like