"illegal else without matching if"

Pages: 12
Can you not see that your braces are all screwed up? If you don't know how a if/else statement is supposed to be braced, then you need to read a book on how to program in c/c++.
Again, I apologize for my lack of knowledge on the subject....This is only the second program I have written and the first was even more basic. I do not have the knowlege that you do and that is why I am here for help. I appreciate any help you can give me, however, I don't really appreciate being talked down to despite my lack of exposure and experience in C++.
You are not being talked down to. You are being told what you need to do if you're going to learn to program in c/c++. The problem you are having should not even be a problem in ANY programming class because the problem you are having is so utterly basic.

In any case, here's what you need to know...

For EVERY "if" statement and for EVERY "else" statement you need to have BOTH an opening brace and a closing brace. Single-line statements are an exception, but until you learn the basics that exception should be ignored.

To solve your problem, go back through your code and make sure that for EVERY "if" statement and for EVERY "else" statement there is BOTH an opening brace and a closing brace. And make sure there is only ONE opening brace and ONE closing brace for EVERY "if" statement and EVERY "else" statement.

You cannot do this, which is what you've done...

1
2
3
4
5
if(whater)
          {
          else
          {
          {


In the above example, you have THREE opening braces and NO closing braces, and you also do not have a closing brace BEFORE the "else" condition.
ok, I will go back through and check that out thank you
Thank you all very much for your time! It is much appreciated.
If you still get errors, post the section of the code and the error message. Also, you've seen us gripe about formatting because formatting is EXTREMELY important in programming, so good formatting is a VERY GOOD HABIT to get into right from the start. The best programmers are also usually the best formatters. It shows attention to detail, and it makes code MUCH easier to read and MUCH easier to maintain.
Topic archived. No new replies allowed.
Pages: 12