Make the user type an odd number within a number range (with try…catch)?

I'm not handing you an answer as this is obviously homework, but I can try to lead you down the right path.

I'm not handing you an answer as this is obviously homework, but I can try to lead you down the right path. Your requirements and program flow: Read input. Parse it as an integer, return error upon failure.

Ensure that it is > 10 and If you want more info then please post what you have already tried and we can help point you in the right direction.

This feels like homework so I'll offer a hint rather than a solution. The point of the exercise seems to be to use exceptions to control program flow (not a good idea, see my comment below the question). Odd numbers have the lowest bit set.

Even numbers do not. If you mask a number with 0x0001 (or just 1... e.g. MyInput & 1), the result is either 0 for an even number or 1 for an odd number. If you divide any number by zero, that will throw an Exception...

It's really pointless and even stupid to use exceptions and try...catch in this case because this could be solved with simple if...else statements. Throwing an exception is always bad for performance. If you must use try..catch, do something like this: // CODE REMOVED However, like I said, this is really stupid way to do this, so use if..else.

And as you can see even this uses if...else to find out whether throw exception or not so :| EDIT: Oh, this is a homework. Then I will just give you couple of hints. Use % operator to find out whether it is odd number or not ( like this: value % 2 == 0 ( or 1 ) ) and use throw new Exception() to throw an exception.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions