so I just started programming and I started with c#. In the book I'm reading (learning c# 3.0), one of the exercises was this.
Exercise 5-2. Create a program that prompts a user for input, accepts an integer, then evaluates whether that input is zero, odd or even, a multiple of 10, or too large (more than 100) by using multiple levels of if statements.
I managed to to this but the next exercise was
Exercise 5-3. Rewrite the program from Exercise 5-2 to do the same work with a switch statement.
I understand how switch statements work, but, I'm not sure how to work out if the user input number is odd/even, multiple of 10 and so on, and not use an if statement. Thank you for any help.
switchstatement. Of course @BenjaminGruenbaum is right anyif (b) { ... } else { ... }can be rewritten intoswitch (b) { case true: ...; break; default: ...; break; }but that is not a realistic use. You could take "odd or even" and "multiple of 10" together, assuming you made sure the number was not negative, by switching onnum % 10, but I don't think that is a realistic use either.