0

Error: expected expression (see photo)

Photo of code and error

It's a very basic program and I'm sure I've made a simple syntax error. There shouldn't be a ";" at the end of the else line and I have included the ; at the end of the printf command. I'm struggling to see anything else (no pun intended) that is wrong. Can anyone help me with this.

Thanks Ross

1

The if/else if/else conditions are used in the following way:

Single condition

if (condition)
{
    // code to execute
}

Double condition

if (condition)
{
    // code to execute
}
else
{
    // code to execute
}

Multiple condition

if (condition)
{
    // code to execute
}
else if (condition2)
{
    // code to execute
}
else if (condition3)
{
    // code to execute
}
...
else
{
    // code to execute
}

You have a condition after your else and that's why you get the compilation error.


If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark. And don't forget to keep coding!

| improve this answer | |
1

else is your last resort kind of command its like if this then { do this } or else if this then { do that } and finally when you cant think of any other condition you say you know what MR Computer if none of the conditions are met. else just do this

you said else and then gave a condition. So the computer is yelling at you that " First you said you want me to do this as long as the conditions arent met now you are giving me a condition? Make up your mind HUMAN." so you should do else if(n < 0)

or if you dont want a condition and say as long as the above two conditions are met do this you just use else { }

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .