M. Howlett
M. Howlett

Reputation: 28

error: expected identifier before '(' token

On the if statements, it keeps on giving me the error:

expected identifier before '(' token

I was banking on this to work.

void setup() 
{
  Serial.begin(9600);
  Serial.println("We will be calculating whether or not ");
  Serial.println("you are underweight, normal, overweight, or obese. ");
}

void loop()
{
  float weight;
  float height;
  float BMI = (703 * weight) / (height * height);

  Serial.println("Please input your weight (pounds)");
  while (Serial.available() <= 0);
  weight = Serial.parseInt();
  Serial.println("Please input your height (inches)");
  while (Serial.available() <= 0);
  height = Serial.parseInt();

  if ( BMI < 18.5 )
  {
    Serial.println("Your body mass index is:");
    Serial.println(BMI);
    Serial.println("please wait while I calculate your weight status");
    Serial.println("...");
    delay(500);
    Serial.println("You are underweight, please go eat.");
  }
  if ( BMI >= 18.5 ) && (BMI <= 24.9)
  {
    Serial.println("Your body mass index is:");
    Serial.println(BMI);
    Serial.println("please wait while I calculate your weight status");
    Serial.println("...");
    delay(500);
    Serial.println("Congratulations! You are a normal");
    Serial.println("... kind of.");
  }
  if (BMI >= 25.0) && (BMI <= 29.9)
  {
    Serial.println("Your body mass index is:");
    Serial.println(BMI);
    Serial.println("please wait while I calculate your weight status");
    Serial.println("...");
    delay(500);
    Serial.println("You are Overweight");
    Serial.println("I suggest a jog");
  }
  if ( BMI >= 30.0)
  {
    Serial.println("Your body mass index is:");
    Serial.println(BMI);
    Serial.println("please wait while I calculate your weight status");
    Serial.println("...");
    delay(500);
    Serial.println("You are OBESE.");
    Serial.println("You have no hope.);
   }
}

Upvotes: 1

Views: 13798

Answers (1)

hexerei software
hexerei software

Reputation: 3160

That should be easy fixing. Your Problem should be easily fixed, if you change these lines:

if ( BMI >= 18.5 ) && (BMI <= 24.9) 

to the correct form is

if (( BMI >= 18.5 ) && (BMI <= 24.9))

your if statement should just have one pair of () around its conditions :)

Upvotes: 4

Related Questions