Write the definition of a function named alternator that receives no parameters and returns true the first time it is invoked, returns false the next time it is invoked, then true, false and so on, alternating between true/false on successive invocations.
.
.
Click on the title for the solution
.
.
bool alternator()
{
static int numCall = 0;
numCall++;
if( numCall%2 == 1 )return true;
else return false;
}
.
Click on the title for the solution
.
.
This is the answer:
:
bool alternator()
{
static int numCall = 0;
numCall++;
if( numCall%2 == 1 )return true;
else return false;
}
Comments
Post a Comment