user2375589
user2375589

Reputation: 55

Arduino application: else without if but has a if

i have some code here, says i have an else without an previous if, the thing is there is a if. And also HOW do i use modulo in here, says invalid binary operator???

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
}

void loop() {
  delay(500);
  int sensorval = analogRead(A0);
  float outval = (sensorval/1024.0) * 5.0;
  float cel =(outval - .5) * 100;
  float far = (cel*1.8000000)+32;
  lcd.setCursor(0,0);
  lcd.print("Farien ");
  lcd.print(far,6);

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  double secs = (millis()/1000);

  if(secs <= 60.0);
  {
      lcd.print(millis()/1000);
  }
  else
  {
    double hrs = (millis()/1000) / 3600.0;
    double mins = hrs / 60.0;
    double secs = mins % 60;
  }
}

THis seems simple enough but i am a rookie and need some major help

Upvotes: 0

Views: 5018

Answers (1)

Udo Klein
Udo Klein

Reputation: 6912

Your if code

  if(secs <= 60.0);

has a redundant semicolon which terminates the statement. Thus the following block is an unconditional block and consequently the else statement leads to an error.

With regard to the modulo operation: the compiler does not state "invalid operator". It states "invalid operands of types 'double' and 'int' to binary operator%". This inplies that you shall not mix doubles and int for this. I would suggest to move away from double and witch completely to integers (e.g. uint32_t).

Upvotes: 1

Related Questions