Why is my variable loosing its value?

Why is my variable loosing its value?
I'm working with this code, I think there is still something wrong with the formula but anyway It's not about the formula its about the variable ContR. By principle I should be able to use it as lcd.print(ContR) on the last line of my program but for some reason it won't work so I just make a work around by copying its value to another variable.

int test;
    float dRes;
    float RefV=5.00;
    float ContR;
    float dContR
    test=analogRead(A0);
    dRes=map(test, 0, 1023, 0, 6000);//Map A/D digital data. 6V max
    dRes=(dRes/1000);//To down scale reading to proper value

    if (RefV>dRes){//Do only if there was a voltage drop
    dRes=(RefV-dRes);//Get the voltage drop
    ContR=(dRes/(RefV/10000));//R1=V1/(V2/R2))
    dContR=ContR; //copying the value to another variable (my work arround so it would work with my LCD Display)
    Serial.println(ContR); //<---- OK! displays the right value
    }

//more code here but not relevant, ContR variable was never used again only the dRes variable was reused here.

    Serial.println(ContR);// <---- Displays 0
    lcd.println(ContR);// <---- Displays 0
    lcd.print(dContR);// <---- OK! displays the right value

Could this be a bug?

We need to see the whole sketch.

I have no idea why your code was working, and this probably has nothing to do with the problem, but

float dContR

Should be

float dContR;
float dContR

That would not even compile.


Rob

   Serial.println(ContR);// <---- Displays 0
    lcd.println(ContR);// <---- Displays 0
    lcd.print(dContR);// <---- OK! displays the right value

Have you tried using the same instructions for both variables? Or maybe change the order you use them?

Like

   Serial.println(dContR);// <---- Displays 0
    lcd.println(dContR);// <---- Displays 0
    lcd.print(ContR);// <---- OK! displays the right value

Or

   Serial.println(ContR);// <---- Displays 0
    lcd.print(ContR);// <---- Displays 0
    lcd.print(dContR);// <---- OK! displays the right value

?