I'm writing a program that is suppose to ask the user for 20 integers. My job is to see if the integer is even or odd. I know how to do it with if statements but how do I do it using switch?
The only way I can think of right now is do the if statements first(if it's even, i'll set a string to "e" and if it's odd, set it to "o") then do the switch statement.
if (num % 2 == 0)
{
answer = "e"
}
else if (num % 2 != 0)
{
answer = "o"
}
switch (answer) {
case "e": blahblahblah
case "o": blah blah blah
}
I know this is a very stupid way of doing it. So is there any smarter way? And yes, I
must use switch statements.
Thanks!!