Pages: [1]   Go Down
Author Topic: expected initializer before 'int'.  (Read 1699 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

void setup()
{
  Serial.begin(9600); //Set serial baud rate to 9600 bps
  pinMode (10,OUTPUT);
}
void loop ()
  int (valGas , valLDR) ;
    valGas = analogRead(0);
    valLDR = analogRead(1);
 
  Serial.println(valGas,DEC);
  Serial.print (",");
  Serial.println in(valLDR,DEC);
 
 if(valGas<600) {
    digitalWrite (10,High);
  } else }
     digitalWrite (10,Low);
   }
 if (valLDR<400) {
   digitalWrite(11,High);
 } else }
   digitalWrite(11,Low);
   }
  delay (100) ;
  }

i get error when i want to compile this code..can anybody help me to see what is wrong with my code?
Logged

Leighton Buzzard, UK
Offline Offline
Edison Member
*
Karma: 20
Posts: 1318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setup()
{
  Serial.begin(9600); //Set serial baud rate to 9600 bps
  pinMode (10,OUTPUT);
}
void loop ()
  int (valGas , valLDR) ;
    valGas = analogRead(0);
    valLDR = analogRead(1);
 
  Serial.println(valGas,DEC);
  Serial.print (",");
  Serial.println in(valLDR,DEC);
 
 if(valGas<600) {
    digitalWrite (10,High);
  } else }
     digitalWrite (10,Low);
   }
 if (valLDR<400) {
   digitalWrite(11,High);
 } else }
   digitalWrite(11,Low);
   }
  delay (100) ;
  }

makes it easier to read

try

Code:
int valGas;
int valLDR;

or
Code:
int valGas , valLDR ;

no brackets!
Logged

there are only 10 types of people
them that understands binary
and them that doesn't

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry, my bad.

i try both ways..but still error.
Logged

Leighton Buzzard, UK
Offline Offline
Edison Member
*
Karma: 20
Posts: 1318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you also need
Code:
void loop
{
... your code
}

you left out the "{" and "}"
Logged

there are only 10 types of people
them that understands binary
and them that doesn't

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  Serial.println(valgas,DEC);
  Serial.print (",");
  Serial.println(valLDR,DEC);

is this part right?
« Last Edit: September 07, 2011, 06:23:48 am by yazidabdulhamid » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(valGas<600) {
    digitalWrite (10,High);
  } else }
     digitalWrite (10,Low);
   }
 if (valLDR<400) {
   digitalWrite(11,High);
 } else }
   digitalWrite(11,Low);
   }
  delay (100) ;
  }

is this the right way to write if-else statement?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is this part right?
If you want that extra carriage return/line feed in the middle, yes. Seems strange to me, though.

Quote
is this the right way to write if-else statement?
Sort of. The braces are not all facing the right way, and they are not all on separate lines where they belong (in my opinion).
Code:
if(valGas<600)
{
    digitalWrite (10,High);
}
else
{
   digitalWrite (10,Low);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setup()
{
  Serial.begin(9600); //Set serial baud rate to 9600 bps
  pinMode (10,OUTPUT);
}
void loop ()
{
  int valgas , valLDR;
    valgas = analogRead(0);
    valLDR = analogRead(1);

  Serial.println(valgas,DEC);
  Serial.print (",");
  Serial.println (valLDR,DEC);
}
 if(valGas<600)
{
    digitalWrite (10,High);
}
else
{
   digitalWrite (10,Low);
}
 if (valLDR<400)
{
   digitalWrite(11,High);
}
else
{
   digitalWrite(11,Low);
   }
  delay (100) ;
  }

this is my current coding,
however, i still got error at this part

Code:
if(valGas<600)
{
    digitalWrite (10,High);
}
else
{
   digitalWrite (10,Low);
}
 if (valLDR<400)
{
   digitalWrite(11,High);
}
else
{
   digitalWrite(11,Low);
   }
  delay (100) ;
  }
Logged

Leighton Buzzard, UK
Offline Offline
Edison Member
*
Karma: 20
Posts: 1318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

look at you code
you have { and } all over the place

you should have
Code:
void loop()
{
  .. all of your code
  if (condition)
  {
    .. true code
  }
  else
  {
    ... false code
  }
}

use indents to help you keep track
and check matching { and }
Logged

there are only 10 types of people
them that understands binary
and them that doesn't

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The IDE has a menu, Tools. On that menu, there is an item, Auto Format. Do your self a favor. Use that tool. Often. It will fix all your random indents. It will also line up all your curly braces, indenting in and out as required. When it gets to the end of a function, and there are still closing } left over, they will bot be indented, leaving you a big clue that the number of open and close braces don't match.

ALL code needs to be inside a function. Not all of yours is. Why not?
Logged

Pages: [1]   Go Up
Jump to: