If Statement Troubles!

I am having trouble finding my error here… might be something simple but my if statements arent behaving as expected. The value im reading in is between 0-60 then put into an integer (printfuellevel) and I can verify my value is 26, yet im having full bar writebar(16) written to the screen.

void getfuellevel()
{
  fuellevel=analogRead(A1);
  fuellevel=fuellevel/16.05;
  lcd.setCursor(13,0);
  printfuellevel=(fuellevel*10)/(10);
  lcd.print(printfuellevel);
  if(printfuellevel==0)
  {
    lcd.setCursor(14,0);
    lcd.write(" ");
  }
  
  lcd.setCursor(15,0);
  lcd.write("L");
  lcd.setCursor(15,1);
  lcd.setCursor(0,1);
  if(printfuellevel<2)
  {
    writeblankbottomrow();
    lcd.write("LOW FUEL");
  }
  if((printfuellevel>2) && (printfuellevel<4))
  {
    writeblankbottomrow();
    writebar(1);
  }
  if((printfuellevel>=4) && (printfuellevel<8))
  {
    writeblankbottomrow();
    writebar(2);
  }
  if((printfuellevel>=8) && (printfuellevel<12))
  {
    writeblankbottomrow();
    writebar(3);
  }
  if((printfuellevel>=12) && (printfuellevel<16))
  {
    writeblankbottomrow();
    writebar(4);
  }
  if((printfuellevel>=16) && (printfuellevel<20))
  {
    writeblankbottomrow();
    writebar(5);
  }
  if((printfuellevel>=20) && (printfuellevel<24));
  {
    writeblankbottomrow();
    writebar(6);
  }
  if((printfuellevel>=24) && (printfuellevel<28))
  {
    writeblankbottomrow();
    writebar(7);
  }
  if((printfuellevel>=28) && (printfuellevel<30))
  {
    writeblankbottomrow();
    writebar(8);
  }
  if((printfuellevel>=30) && (printfuellevel<32))
  {
    writeblankbottomrow();
    writebar(9);
  }
  if((printfuellevel>=32) && (printfuellevel<36))
  {
    writeblankbottomrow();
    writebar(10);
  }
  if((printfuellevel>=36) && (printfuellevel<40))
  {
    writeblankbottomrow();
    writebar(11);
  }
  if((printfuellevel>=40) && (printfuellevel<44));
  {
    writeblankbottomrow();
    writebar(12);
  }
  if((printfuellevel>=44) && (printfuellevel<48))
  {
    writeblankbottomrow();
    writebar(13);
  }
  if((printfuellevel>=52) && (printfuellevel<56))
  {
    writeblankbottomrow();
    writebar(14);
  }
  if((printfuellevel>=56) && (printfuellevel<58))
  {
    writeblankbottomrow();
    writebar(15);
  }
  if((printfuellevel>58))
  {
    writeblankbottomrow();
    writebar(16);
  }
  
}

if((printfuellevel>=20) && (printfuellevel<24));Oops

Could be that the problem is in writebar().

  if((printfuellevel>=44) && (printfuellevel<48))
...  
   if((printfuellevel>=52) && (printfuellevel<56))

Not the problem you are trying to solve but you also have a gap here that I think is unintentional.

Please post the whole of your code. Presumably the writebar() function writes a 'thermometer' style bar on the LCD but without the whole code it is impossible to be of any help.

AWOL:
if((printfuellevel>=20) && (printfuellevel<24));Oops

This mistake occurs twice and would result in spurious calls to writeblankbottomrow(); writebar(6); writeblankbottomrow(); writebar(12); - what effect would that have on the display?

Also notice that you don’t do anything when (printfuellevel == 58).

This code is very unfinished at the moment but does compile, might not make sense logically, the if statement is still having troubles… hope this helps…

/* 
Carduino
by: Kai Rasporich
*/
#include <LiquidCrystal.h>
//SET UP DISPLAY//
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 6);
int backLight = 13;
int ledPin = 13; // LED is attached to digital pin 13
int x = 15; // variable to be updated by the interrupt
int lastxvalue = 15;
float batterylevel;
int voltage;
float fuellevel;
int printfuellevel;
float coolanttemp;
int printcoolanttemp;
float consumption;
int printconsumption;
//DEFINE CHAR
byte fullbar[8] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};
byte blank[8] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
};
byte degree[8] = {
  B01110,
  B10001,
  B01110,
  B00000,
  B00000,
  B00000,
  B00000,
};

//variables to keep track of the timing of recent interrupts
unsigned long button_time = 0;  
unsigned long last_button_time = 0; 
unsigned long checkbutton_time = 0;  
unsigned long checklast_button_time = 0; 
int lastcall=0;

void setup() {                
  //enable interrupt 0 which uses pin 2
  //jump to the increment function on falling edge
  digitalWrite(2, HIGH);
  attachInterrupt(0, increment, FALLING);
  //Serial.begin(9600);  //possibly corrupting stream..
  pinMode(backLight, HIGH);
  digitalWrite(backLight, HIGH);
  Serial.begin(9600);
  lcd.begin(16,2);              // columns, rows.  use 16,2 for a 16x2 LCD, etc.
  lcd.clear();
  startUpRoutine();
}

void loop() {
  loadmenu();
}

// Interrupt service routine for interrupt 0
void increment() {
  button_time = millis();
  //check to see if increment() was called in the last 250 milliseconds
  if (button_time - last_button_time > 350)
  {
    lastxvalue = x;
    if(x!=19)
    {
      x++;
      lastcall=0;
    }
    else
    {
      x=15;
    }
    last_button_time = button_time;
    delay(100);
  }
}

void loadmenu()
{
    if(x==15)
    {
      clearfunction();
      lcd.setCursor(0,0);
      lcd.write("Fuel Level:  ");
      if(lastcall==0)
      {
         getfuellevel();  
      }
      lastcall=lastcall+1;
      if (lastcall > 30)
      {    
         getfuellevel(); 
      } 
      if(lastcall==31)
      {
         lastcall=1;
      } 
      delay(85);
    }  
    if(x==16)
    { 
      clearfunction();
      lcd.setCursor(0,0);
      lcd.write("Fuel Consumption");
      //Test some functionality
      if(lastcall==0)
      {
         getfuelconsumption();
      }
      lastcall=lastcall+1;
      //check to see if increment() was called in the last 250 milliseconds
      if (lastcall > 20)
      {    
          getfuelconsumption();
      } 
      if(lastcall==21)
      {
        lastcall=1;
      }  
    }
    if(x==17)
    {
      clearfunction();
      lcd.setCursor(0,0);
      delay(400);
      fuellevel=analogRead(A1);
      lcd.write("Fuel: ");
      printfuellevel=(fuellevel*100)/100;
      lcd.print(printfuellevel);
      lcd.setCursor(0,1);
      lcd.write("Coolant: ");
      coolanttemp=analogRead(A2);
      printcoolanttemp=(coolanttemp*100)/(100);
      lcd.print(printcoolanttemp); 
      delay(400);     
    }
    if(x==18)
    {
      clearfunction();
      lcd.setCursor(0,0);
      lcd.write("Battery Gauge:");
      if(lastcall==0)
      {
         getbatterylevel();
      }
      if (lastcall > 20)
      {    
         getbatterylevel();
      }
      if(lastcall==21)
      {
        lastcall=1;
      }    
    }
    if(x==19)
    {
      clearfunction();
      lcd.setCursor(0,0);
      lcd.write("Run Temp:");
      getcoolanttemp();
    }
    if(x==20)
    {
      clearfunction();
      lcd.setCursor(0,0);
      lcd.write("Outside Temp:");
      lcd.setCursor(0,1);
      lcd.write("Disconnected...");
      getcoolanttemp();
    }
    lastxvalue = x;
}

void startUpRoutine()
{
  lcd.write("//MPOWER");
  lcd.createChar(0, fullbar);
  lcd.createChar(1, blank);
  lcd.createChar(2, degree);
  lcd.setCursor(0,1);
  lcd.write("Welcome Kai");
  delay(1500);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.write("Loading:");
  delay(500);
  lcd.setCursor(8,0);
  lcd.write("Library");
  delay(500);
  lcd.clear();
  lcd.write("Loading:");
  lcd.setCursor(8,0);
  lcd.write("Data");
  lcd.setCursor(0,1);
  for(int i=0; i<=10; i++)
  {
  lcd.write((uint8_t)0);
  delay(85);
  }
  lcd.setCursor(8,0);
  lcd.write("Sync");
  lcd.setCursor(8,0);
  delay(500);
  lcd.setCursor(8,0);
  lcd.write("Gauge");
  lcd.setCursor(11,1);
  for(int i=0; i<=7; i++)
  {
  lcd.write((uint8_t)0);
  delay(85);
  }
  
  digitalWrite(backLight, LOW);
  lcd.clear();
  delay(40);
  digitalWrite(backLight, HIGH);
}

void clearfunction(){
  if(lastxvalue!=x)
  {
    lcd.clear();
  }
}

void writeblankbottomrow()
{
  for(int i=0; i<=1; i++)
  {
     lcd.write((uint8_t)1);
  }
}

void writebar(int num)
{
  lcd.setCursor(0,1);
  for(int i=0; i<=num; i++)
  {
     lcd.write((uint8_t)0);
  }
}

void getfuellevel()
{
  fuellevel=analogRead(A1);
  fuellevel=fuellevel/16.05;
  lcd.setCursor(13,0);
  printfuellevel=(fuellevel*10)/(10);
  lcd.print(printfuellevel);
  if(printfuellevel==0)
  {
    lcd.setCursor(14,0);
    lcd.write(" ");
  }
  
  lcd.setCursor(15,0);
  lcd.write("L");
  lcd.setCursor(15,1);
  lcd.setCursor(0,1);
  if(printfuellevel<2)
  {
    writeblankbottomrow();
    lcd.write("LOW FUEL");
  }
  if((printfuellevel>2) && (printfuellevel<4))
  {
    writeblankbottomrow();
    writebar(1);
  }
  if((printfuellevel>=4) && (printfuellevel<8))
  {
    writeblankbottomrow();
    writebar(2);
  }
  if((printfuellevel>=8) && (printfuellevel<12))
  {
    writeblankbottomrow();
    writebar(3);
  }
  if((printfuellevel>=12) && (printfuellevel<16))
  {
    writeblankbottomrow();
    writebar(4);
  }
  if((printfuellevel>=16) && (printfuellevel<20))
  {
    writeblankbottomrow();
    writebar(5);
  }
  if((printfuellevel>=20) && (printfuellevel<24));
  {
    writeblankbottomrow();
    writebar(6);
  }
  if((printfuellevel>=24) && (printfuellevel<28))
  {
    writeblankbottomrow();
    writebar(7);
  }
  if((printfuellevel>=28) && (printfuellevel<30))
  {
    writeblankbottomrow();
    writebar(8);
  }
  if((printfuellevel>=30) && (printfuellevel<32))
  {
    writeblankbottomrow();
    writebar(9);
  }
  if((printfuellevel>=32) && (printfuellevel<36))
  {
    writeblankbottomrow();
    writebar(10);
  }
  if((printfuellevel>=36) && (printfuellevel<40))
  {
    writeblankbottomrow();
    writebar(11);
  }
  if((printfuellevel>=40) && (printfuellevel<44));
  {
    writeblankbottomrow();
    writebar(12);
  }
  if((printfuellevel>=44) && (printfuellevel<48))
  {
    writeblankbottomrow();
    writebar(13);
  }
  if((printfuellevel>=52) && (printfuellevel<56))
  {
    writeblankbottomrow();
    writebar(14);
  }
  if((printfuellevel>=56) && (printfuellevel<58))
  {
    writeblankbottomrow();
    writebar(15);
  }
  if((printfuellevel>58))
  {
    writeblankbottomrow();
    writebar(16);
  }
  
}

void getfuelconsumption()
{
  lcd.setCursor(0,1);
  fuellevel=analogRead(A1);
  //Calculation Here to get litres of fuel
  printconsumption=(fuellevel/11.7607)*100;
  printconsumption=(printconsumption*100)/100;
  lcd.print(printconsumption);
  lcd.setCursor(3,1);
  lcd.write("km");
  delay(100);
}

void getbatterylevel()
{
  lcd.setCursor(4,1);
  batterylevel=analogRead(A0);
  batterylevel=((batterylevel)/(40.199818347))*100;
  voltage = (batterylevel);
  lcd.print(voltage%10, 10);
  lcd.setCursor(3,1);
  voltage = voltage/10;
  lcd.print(voltage%10, 10);
  lcd.setCursor(2,1);
  lcd.write(".");
  lcd.setCursor(1,1);
  voltage = voltage/10;
  lcd.print(voltage%10, 10);
  voltage = voltage/10;
  if (voltage >= 1)
  {
      lcd.setCursor(0,1);
      lcd.print(voltage%10, 10);
  }
  else
  {
      lcd.setCursor(0,1);
      lcd.print(0);
  }
  lcd.setCursor(5,1);
  lcd.write("V");
}

void getcoolanttemp()
{
  coolanttemp=analogRead(A2);
  printcoolanttemp=(coolanttemp*100)/(100);
  lcd.setCursor(11,0);
  lcd.print(printcoolanttemp);
  lcd.write((uint8_t)2);
  lcd.write("C");
  lcd.setCursor(0,1);
  lcd.print(coolanttemp);
  delay(100);
}

the if statement is still having troubles..

Don't bother to describe what those troubles might be. We'll guess. Or maybe not.

kairaspo:
This code is very unfinished at the moment but does compile, might not make sense logically, the if statement is still having troubles… hope this helps…

You haven’t corrected the problems that have already been pointed out: Your number ranges are not contiguous, and there are spurious semicolons which will cause code blocks to be executed inappropriately. There seems little point us looking at it any further unless you correct the known problems.

void getfuellevel()
{
    fuellevel = analogRead(A1);
    fuellevel = fuellevel / 16.05;
    lcd.setCursor(13, 0);
    printfuellevel = (fuellevel * 10) / (10);
    lcd.print(printfuellevel);
    if ( printfuellevel == 0 )
    {
        lcd.setCursor(14, 0);
        lcd.write(" ");
    }

    lcd.setCursor(15, 0);
    lcd.write("L");
    lcd.setCursor(15, 1);
    lcd.setCursor(0, 1);

    if ( printfuellevel < 2 )
    {
        writeblankbottomrow();
        lcd.write("LOW FUEL");
    }

// ??? HEY -WHAT ABOUT 2 INSELF ???

    else if ( (printfuellevel > 2) && (printfuellevel < 4) )
    {
        writeblankbottomrow();
        writebar(1);
    }
    else if ( (printfuellevel >= 4) && (printfuellevel < 8) )
    {
        writeblankbottomrow();
        writebar(2);
    }
    else if ( (printfuellevel >= 8) && (printfuellevel < 12) )
    {
        writeblankbottomrow();
        writebar(3);
    }
    else if ( (printfuellevel >= 12) && (printfuellevel < 16) )
    {
        writeblankbottomrow();
        writebar(4);
    }
    else if ( (printfuellevel >= 16) && (printfuellevel < 20) )
    {
        writeblankbottomrow();
        writebar(5);
    }
    else if ( (printfuellevel >= 20) && (printfuellevel < 24) )
    {
        writeblankbottomrow();
        writebar(6);
    }
    else if ( (printfuellevel >= 24) && (printfuellevel < 28) )
    {
        writeblankbottomrow();
        writebar(7);
    }
    else if ( (printfuellevel >= 28) && (printfuellevel < 30) )
    {
        writeblankbottomrow();
        writebar(8);
    }
    else if ( (printfuellevel >= 30) && (printfuellevel < 32) )
    {
        writeblankbottomrow();
        writebar(9);
    }
    else if ( (printfuellevel >= 32) && (printfuellevel < 36) )
    {
        writeblankbottomrow();
        writebar(10);
    }
    else if ( (printfuellevel >= 36) && (printfuellevel < 40) )
    {
        writeblankbottomrow();
        writebar(11);
    }
    else if ( (printfuellevel >= 40) && (printfuellevel < 44) )
    {
        writeblankbottomrow();
        writebar(12);
    }
    else if ( (printfuellevel >= 44) && (printfuellevel < 48) )
    {
        writeblankbottomrow();
        writebar(13);
    }

// ??? HEY -WHAT ABOUT 48 - 51 ???

    else if ( (printfuellevel >= 52) && (printfuellevel < 56) )
    {
        writeblankbottomrow();
        writebar(14);
    }
    else if ( (printfuellevel >= 56) && (printfuellevel < 58) )
    {
        writeblankbottomrow();
        writebar(15);
    }
    else if ( (printfuellevel > 58) )
    {
        writeblankbottomrow();
        writebar(16);
    }
}

… or not Standard C++ but will work with ALL known GNU based Arduino API IDE …

void getfuellevel()
{
    lcd.setCursor(13, 0);
    fuellevel = analogRead(A1);
    fuellevel = fuellevel / 16.05;
    printfuellevel = (fuellevel * 10) / (10);
    lcd.print(printfuellevel);
    if ( printfuellevel == 0 )
    {
        lcd.setCursor(14, 0);
        lcd.write(" ");
    }

    lcd.setCursor(15, 0);
    lcd.write("L");
    lcd.setCursor(15, 1);
    lcd.setCursor(0, 1);

    switch ( printfuellevel )
    {
        case 0 ... 1:
            writeblankbottomrow();
            lcd.write("LOW FUEL");
            break;
            
// ??? HEY -WHAT ABOUT 2 INSELF ???

        case 3:
            writeblankbottomrow();
            writebar(1);
            break;
            
        case 4 ... 7:
            writeblankbottomrow();
            writebar(2);
            break;
            
        case 8 ... 11:
            writeblankbottomrow();
            writebar(3);
            break;
            
        case 12 ... 15:
            writeblankbottomrow();
            writebar(4);
            break;
            
        case 16 ... 20:
            writeblankbottomrow();
            writebar(5);
            break;
            
        case 20 ... 23:
            writeblankbottomrow();
            writebar(6);
            break;
            
        case 24 ... 27:
            writeblankbottomrow();
            writebar(7);
            break;
            
        case 28 ... 29:
            writeblankbottomrow();
            writebar(8);
            break;
            
        case 30 ... 31:
            writeblankbottomrow();
            writebar(9);
            break;
            
        case 32 ... 36:
            writeblankbottomrow();
            writebar(10);

        case 35 ... 39:
            writeblankbottomrow();
            writebar(11);
            break;
            
        case 40 ... 43:
            writeblankbottomrow();
            writebar(12);
            break;
            
        case 44 ... 47:
            writeblankbottomrow();
            writebar(13);
            break;
            
// ??? HEY -WHAT ABOUT 48 - 51 ???

        case 52 ... 55:
            writeblankbottomrow();
            writebar(14);
            break;
            
        case 56 ... 57:
            writeblankbottomrow();
            writebar(15);
            break;
            
        default:
            writeblankbottomrow();
            writebar(16);
            break;
    }
}

Ah yes I need the 48-51!! so dumb somedays!!! Sorry about the rough code, but I have zero coding experience, everything is learnt off the youtube.