Some questions on conditional statements
- What is wrong with each of the following statements?
- if x==4 y++;
Missing parentheses around the comparison. Should be
if(x==4) y++;
- if(x=4) ++y;
Assignment instead of comparison. Should be
if(x==4) y++;
- if (x==4) ++y else --y;
Missing missing semi-colon at the end of ++y. Should be
if(x==4) ++y; else --y;
Remember that the semi-colon is a statement terminator, not a statement
separator.
- Write a program which reads in two integer numbers and writes out the larger
of the two.
You may want to refer ahead to find out how to read
innumbers or write them out.
FInd a sample answer here.
¥
Back to the questions.
Back to the notes on conditionals.