I need to write a lottery game application that will generate three random numbers each between 0 and 9. The user should guess three numbers and the program should compare each of the user's guess to the three random and display an appropriate output based on whether they got:
-any one matching
-two matching
-three matching, not in order
-three matching in exact order
-or no matches at all
The major catch here is that I cannot use any loops whatsoever. I have to do this using only if conditions and or switch statements. I cannot use functions, arrays or anything advanced only if and or switch. Is this possible to do without having to do if conditions for every single possible combination? I've tried using counters to narrow things down but that only got me more confused. Can anyone help point me in the right direction? Thanks.
What I have so far just checks for one matching, three matching in order, or none matching
Really glad I never took an assignment this annoying. I haven't thought of any methods yet that could make this less repetitive but I do see some problems with your current logic statements.
This statement only verifies that none match in order, the number guessed can still match out of order.(Dont understand why out of order has to be checked seeing how lotteries aren't won this way) .
This statement only checks if one of the 3 comparisons are true. You can guess two correct numbers and this would still execute saying you guessed one right.
Thanks for the corrections. Now my head hurts even more lol. I may just have to write out all the combinations although I'm sure I'll lose "efficiency points"....
You could probably use nested if statements to simply your life a bit. Regardless, this is a really silly assignment (at what point would you need to do something like this in industry?)
With out a doubt. I think switch would be your friend here though coupled with a bunch of ifs.
How much order counts plays a big part too, since three out of order is considered does two out of order count as matching or is that only only relevant to three since that is the only condition "out of order" is mentioned. It simplifies greatly if order only matters for all the numbers.
You could probably use nested if statements to simply your life a bit. Regardless, this is a really silly assignment (at what point would you need to do something like this in industry?)
It's not about using something in the industry, it is about making you understand and learn languages and features. In this case it is a "silly assignment" that apparently is to help solidify the use of if statements. Though, I wouldn't call an assignment silly as all programs you write just help solidify what you are learning.
My question is: Why are they only comparing one match or all three matches? Shouldn't they get a prize for matching two?
Yeah, it is a silly and somewhat pointless assignment; it teaches very little in return for the effort. Learning conditional statements is not about writing the same conditional statement with different variables over and over and over again - it does not "solidify" anything worthwhile. Learning programming is not about writing the same (or almost the same) program in the same amateurish way, year after year for a dozen or more years.
@AnEndingAscent, you may find that keeping a count of exact and inexact matches would simplify the code.