error message

cpp: 40:1:error: expected unqualified-id before token '{'
My sketch is:

#include <LiquidCrystal.h>

//LiquidCrystal display with:

//rs on pin 12

//rw on pin 11

// enable on pin 10

//d4-7 on pins 5-2

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup()

{
Serial.begin(9600);

lcd.begin(2, 20);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Evil Genius");

lcd.setCursor(0,1);

lcd.print("Rules");

}

void loop();

{
if (Serial.available())
{
char ch = Serial.read();
if (ch == '#')
}
lcd.clear();

}

else if (ch == '/')
{
lcd.setCursor(0,1);
}
else
{
lcd.write(ch);

}
}
}

Need help, Thanks.

Remove the semicolon.

void loop();

Adding semicolons sometimes does not hurt, but sometimes it does.

Additionally:

    if (ch == '#')
  }

does not make sense, neither.

You could add a semicolon here, but I'm not sure this will behave according to your intention

Next time: code tags, indentation, and a closer look by yourself :wink:

Thanks for the code, but, I can't read it. Can you take out most (all) of those blank lines, and use the menu bar "tools-Auto Format"?
then upload it again. That made my 64 year old eyes start to hurt. LOL

I can tell you now that trying to use Tools -> Auto Format will fail. However, in doing so it will tell you why your program won't compile.

@majenko, the Auto Format will fail, not reformat his sketch? Why do you think that?

jackwp:
@majenko, the Auto Format will fail, not reformat his sketch? Why do you think that?

For the same reason that the OP is getting an error message. I could tell you the error that Auto Format comes up with, but that would spoil the fun.

Ok, I will try to be patient, and see what the OP tells us.

I tried semi colon on void loop, Surfer Tim. It gave more error messages. I will paste the result from auto format even though I don't know what that is.These are my baby steps in Arduino. This sketch is from a book"30 Arduino projects for the Evil Genius by Simon Monk. Thanks for the replies.

This is after auto format

#include <LiquidCrystal.h>

//LiquidCrystal display with:

//rs on pin 12

//rw on pin 11

// enable on pin 10

//d4-7 on pins 5-2

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup()

{
Serial.begin(9600);

lcd.begin(2, 20);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Evil Genius");

lcd.setCursor(0,1);

lcd.print("Rules");

}

void loop();

{
if (Serial.available())
{
char ch = Serial.read();
if (ch == '#')
}
lcd.clear();

}

else if (ch == '/')
{
lcd.setCursor(0,1);
}
else
{
lcd.write(ch);

}

Think this could be a problem?

if (Serial.available())
  {
    char ch = Serial.read();
    if (ch == '#')
    }
    lcd.clear();

}

I will paste the result from auto format even though I don't know what that is.

If you don't know what Auto Format is (it's a entry in the Tools menu), how are you going to use it?

This is after auto format

No, it isn't.

Well, you have made enough changes that autoformat thinks it has worked now (no error from it), however it has failed completely because there are still errors in your program.

Things you will do before you post again:

  1. Remove all the extra blank lines from your program so it is actually readable.
  2. Manually reformat your code. Place every { on the line beneath the command it goes with, and indent lines up to its matching }
  3. Look for any extraneous ; that have already been pointed out to you that you still haven't removed.

Your properly formatted code should look like this:

else if (ch == '/')
{
    lcd.setCursor(0,1);
}
else
{
    lcd.write(ch);
}

As you work through your code sorting out the indentation you will see your problem.

And then, when you are done, post your cleaned up code in [code][/code] tags.

Majenko, is this what you are expecting? Thanks for the suggestions.It still doesn't compile.

``#include <LiquidCrystal.h>
//LiquidCrystal display with:
//rs on pin 12
//rw on pin 11
// enable on pin 10
//d4-7 on pins 5-2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
lcd.begin(2, 20);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Evil Genius");
lcd.setCursor(0,1);
lcd.print("Rules");
}
void loop()

{if (Serial.available())
{
char ch = Serial.read()
if (ch == '#')
}
lcd.clear()
}
else if (ch == '/')
{
lcd.setCursor(0,1);
{
else
{
lcd.write(ch);
}
}
}

...post your cleaned up code in tags.

I very much doubt that the code in Simon Monk's book is the same as yours, so you have two choices: go back to the text and compare line by line with yours and correct it, or debug it. Debugging would stand you in better stead for working on programs of your own. I suggest that you compile your code and fix the first error it reports and repeat until it compiles cleanly. The first error is clear enough - if you get stuck after that, post your most recent code and/or go back to your book for help.

How do I do that. Please give me details.I have no experience in this.Thank you.

I doubt if Monk's book contains the same code you typed in. Remember:

  1. Statements in C end with a semicolon. For example, char ch = Serial.read() without a semicolon isn't going to compile. There are others in your code, too.
  2. Left and right braces are not the same. Use "{" at the start of a statement block and "}" at the end of that statement block.

Thanks.I am sorry I should have read carefully "The how to Post." I am going to do the whole thing all over again and post in code tags.

Hi Everybody, I was wrong in the 1st post. It was my wrong copying the sketch from the book that gave the compiling error. When I went back and redid it there was no error. My apologies to all concerned.Thanks anyway.