Return value of 0 if value is less than zero Background: I am using an analog pressure sensor with a range from 0-100PSI returning voltage values .44v to 4.44v. It's open air (or 0 PSI) voltage on the signal pin is .47 volts. I have a function that subtracts that .47v (to make zero) and then multiplies it by 25 (25 PSI per volt). Due to signal noise or other factors, sometimes my function returns a negative number, which wreaks havoc on my math. I would like to return a value of 0 when my offset math returns a negative number, but I'm having a problem with it. 

The code that I wrote that doesn't work: 

double EngineOilPressure() {
    //insert oil pressure code here
    int reading = analogRead(sensorPin3);
    float voltage = reading * 5.0;
    voltage /=1024.0;

    Serial.print(voltage); Serial.println(" volts");

    if (voltage-.47 &lt; 0)
    {
        float voltadj = 0;
    }
    else
    {
        float voltadj = (voltage-.47);
    }

    float pressureP = voltadj * 25;
    return PSIToPascal(pressureP);
}


The error that I get is 

dynamic_engine.pde: In function 'double EngineOilPressure()':
dynamic_engine.pde:41:23: error: 'voltadj' was not declared in this scope
Error compiling.


The code that works but sometimes returns a very wrong value: 

double EngineOilPressure() {
    int reading = analogRead(sensorPin3);
    float voltage = reading * 5.0;
    voltage /=1024.0;

    Serial.print(voltage); Serial.println(" volts");

    float pressureP = (voltage - .47) * 25;
    return PSIToPascal(pressureP);
}
The scope of each of the two different and unrelated voltadj variables that your code (as below) declares is limited to within its enclosing set of braces.

if (voltage-.47 &lt; 0)
{
    float voltadj = 0;
}
else
{
    float voltadj = (voltage-.47);
}


Instead perhaps say

float voltadj = voltage-.47;
if (voltadj &lt; 0) voltadj = 0;


or perhaps

float voltadj = voltage &lt; .47? 0 : voltage-.47;


or

float voltadj = constrain(voltage-0.47, 0.0, 5.0);


or 

float voltadj = max(0.0, voltage-0.47);


Also see max() and constrain() reference pages at arduino.cc.