Go Down

### Topic: if else problem (Read 558 times)previous topic - next topic

#### julianassan

##### Dec 25, 2011, 01:17 am
int ledPin = 13;
int inputPin = 3;
int val = 0;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
}

void loop()
{
if (inputPin == val );
{
digitalWrite(ledPin, LOW);
}
if else (inputPin == val);
{
digitalWrite(ledPin, HIGH);
}

sketch_dec25b.cpp: In function 'void loop()':
sketch_dec25b:16: error: expected `(' before 'else'
sketch_dec25b:19: error: expected `}' at end of input

what happen i can't understand, pliz help me

#### el_supremo

#1
##### Dec 25, 2011, 01:35 am
The semicolon at the end of this line:
Code: [Select]
`if (inputPin == val );`
terminates the if statement. So it means "if inputPin equals val, do nothing"

The loop() should be:
Code: [Select]
`void loop(){ if (inputPin == val )  {    digitalWrite(ledPin, LOW);  } if else (inputPin == val)  {    digitalWrite(ledPin, HIGH);}`

Pete
Don't send me technical questions via Private Message.

#### julianassan

#2
##### Dec 25, 2011, 02:09 am

sketch_dec25a.cpp: In function 'void loop()':
sketch_dec25a:16: error: expected `(' before 'else'
sketch_dec25a:19: error: expected `}' at end of input

but it send this error

#### julianassan

#3
##### Dec 25, 2011, 02:17 am
i have solve it . thank u for your help

int ledPin = 13;
int inputPin = 3;
int val = 0;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
}

void loop()
{
if (inputPin <= val )
{
digitalWrite(ledPin, LOW);
}
else
{
digitalWrite(ledPin, HIGH);
}
}

Go Up