new to coding and had some issues while writing project 2 spaceship code

I get the error Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

spaceship:1: error: expected unqualified-id before numeric constant

1 int switchState = 0;

^

spaceship:2: error: expected unqualified-id before numeric constant

2 void setup(){

^

spaceship:8: error: expected unqualified-id before numeric constant

8 void loop(){

and my code is:

1 int switchState = 0;
2 void setup(){
3 pinMode(3,OUTPUT);
4 pinMode(4,OUTPUT);
5 pinMode(5,OUTPUT);
6 pinMode(2,INPUT);
7 }
8 void loop(){
9 switchState = digitalRead(2);
10 // this is a comment
11 if (switchState == LOW) {
12 // the button is not pressed

13 digitalWrite(3, HIGH); // green LED
14 digitalWrite(4, LOW); // red LED
15 digitalWrite(5, LOW); // red LED
16 }

17 else { // the button is pressed
18 digitalWrite(3, LOW);
19 digitalWrite(4, LOW);
20 digitalWrite(5, HIGH);

21 delay(250); // wait for a quarter second
22 // toggle the LEDs
23 digitalWrite(4, HIGH);
24 digitalWrite(5, LOW);
25 delay(250); // wait for a quarter second

26 }
27 } // go back to the beginning of the loop

I would be very happy to figure out the issue.

You should not have line numbers.

...R

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

What IDE are you using?
If you need line numbers the Arduino IDE can put them in the margin of your code.

Thanks.. Tom.. :slight_smile:

same here
heres my code

int switchState = 0;
void setup(){
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop()
switchState = digitalRead(2);
// Hello
if (switchState == LOW) {
// the button is not pressed
digitalWrite(3, HIGH); // green LED
digitalWrite(4, LOW); // red LED
digitalWrite(5, LOW); // red LED
}
else { // the button is pressed
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); // wait for a quarter second
// toggle the LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait for a quarter second
}
} // go back to beginning of the loop

void loop()
  switchState = digitalRead(2);

You are missing the { to open the loop() code block.

void loop()
{
  switchState = digitalRead(2);

Read the forum guidelines to see how to post code.

In the future post the entire error message. Paraphrasing leaves out important information.