Why does the 2nd "if" statement have to be "else if"?
If one thing is pressed, print message 1.
If another thing is pressed, print message 2. If not, print message 3.
Can you see that that is not what you want? If nothing if pressed, what gets printed? If only the first thing is pressed, what gets printed? If only the second thing is pressed, what gets printed?
If one thing is pressed, print message 1. If not, if another thing is pressed, print message 2. If not, print message 3.
THAT is what an if/else if/else statement does. Can you see that they are different?
If not, consider this:
if(firstThingPressed)
{
printMessageOne();
}
else
{
if(secondThingPressed)
{
printMessageTwo();
}
else
{
printMessageThree();
}
}
Which of your snippets does that resemble?
An else if statement isn't really a separate statement at all. It simply eliminates the need for a set of curly braces. The above snippet is exactly the same as:
if(firstThingPressed)
{
printMessageOne();
}
else if(secondThingPressed)
{
printMessageTwo();
}
else
{
printMessageThree();
}