I’ve had quite a bit of experience with programming (three semesters teaching VBasic, C++, and Java), and now I’m in college and I’m taking a C# class, which is quite boring (the teacher knows less than I do).
Anyways, for one of our exercises, we’re creating a number guessing/lottery game. It works kind of like this:
- User inputs three integers from 1-4 and clicks submit (I have them storing into an array)
- Program generates three numbers from 1-4 (also in an array)
- Function that checks matching runs and checks the two arrays
- If all three match in order (i.e. 1,2,3 = 1,2,3 and NOT 1,2,3 = 1,3,2), matching = 4
- If all three match NOT in order, matching = 3
- If only two match, matching = 2
- I want to make sure that only one match counts as one (i.e. [1,1,2][1,2,3] only gives one match to the user.
- If only one matches, matching = 1
- If no matches, matching stays at 0 (it’s instantiated at submit_click)
I’ve got all of the code and GUI working except for the matching logic. I know I could do it with a LARGE amount of if statements, and I know cases would probably work, but I’m not as experienced with cases.
I’m not expecting my ‘homework’ to be done here, but I just want to know what method would be most effective to get this to correctly work (if it’s easier to exclude the one match per item, then that’s fine), and to possibly see some working code.
Thanks!
EDIT
I apologize if I come across as arrogant, I didn’t mean to come across as a know-it-all (I definitely do not).
I have NOT taught classes, I’ve just taken classes from a teacher who’s primarily a programming in and I’m at a community college and my professor isn’t primarily a programming teacher.
I didn’t take time to write a ton of if statements because I know that it would just get shot down as ineffective. I currently don’t have the resources to test the answers, but as soon as I can I’ll check them out and post back.
Again, I apologize for coming across as rude and arrogant, and I appreciate your answers more than you know.
Thanks again!
You can use a loop to achieve this functionality. I’ve used a list simply for ease of use, performing
removeoperations and the like. Something like this should work: