I’m experiencing something weird that seems to be related to using a [bool] variable in an if clause. I say “seems” because I haven’t seen this in the past,so perhaps I’m missing something more basic?
If I try to compile with the following in my project, the compiler fails:
if (DoorClosed)
{
DistanceTravelled = 0;
PctOpen = 0.0;
}
else if (DoorOpen)
{
PctOpen = 100.0;
}
else
{
PctOpen = ((double) (DistanceTravelled / 4 )) / FullOpenDist * 100.0;
}
‘DoorClosed’ and ‘DoorOpen’ are global variables defined like this:
bool DoorClosed = false; // Input high when door Closed
bool DoorOpen = false; // Input high when door Open
The compiler gives me the following error:
"garageminder.cpp:7:1: error: expected unqualified-id before 'else'
else if (DoorOpen);
^
However…
if I change the code code like this, the software compiles:
if (DoorClosed == true)
{
DistanceTravelled = 0;
PctOpen = 0.0;
}
else if (DoorOpen == true)
{
PctOpen = 100.0;
}
else
{
PctOpen = ((double) (DistanceTravelled / 4 )) / FullOpenDist * 100.0;
}
NOTE: In case it helps, the above code is in loop().
The really weird thing is that I have other code in the same project where I’ve put a bool variable in an if statement, and
the compiler did not complain! So is this some weird red herring or have I missed something basic?