All, quick and easy one here…
I’m writing an Evaluate function that runs through a bunch of other bool functions. Right now, I’m basically doing an if, else if loop (seen below). Any suggestions on another way of doing this??? I’m assuming I could do this with a switch but have never used them before like this.
int i = 78;
if (isPrime(i))
{
cout <<"is prime" << endl;
return;
}
else if (ismultipleOf23(i))
{
cout <<"is a multiple of 23" << endl;
return;
}
else if (isEven(i))
{
cout <<"is Even" << endl;
return;
}
else if (isOdd(i))
{
cout <<"is Odd" << endl;
return;
}
You can’t use a switch because the labels have to be constant.
What you are doing is the correct way.