I have an example from my textbook that I want clarification on. See below. Let's say my input is 0.5 for the fuelGaugeReading. It's read, goes to the nested IF, noticed it's greater than 0.25, then it produces nothing since it did not meet the requirements of either IF.
My question is, why does it not meet the requirement of the first IF, and therefore outputs the statement from the ELSE?
int main()
{
double fuelGaugeReading;
cout << "Enter fuel gauge reading: ";
cin >> fuelGaugeReading;
cout << "First with braces:\n";
if (fuelGaugeReading < 0.75)
{
if (fuelGaugeReading < 0.25)
cout << "Fuel very low. Caution!\n";
}
else
{
cout << "Fuel over 3/4. Don't stop now!\n";
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire