Well, yeah. You're stepping through the array 1 by 1, starting at the number 1 and going to 55. Of course it's going to give them to you in numerical order. :P
This is why I said you need to look what you want your array[] array to hold. You have it set to hold 56 integers, which implies you want to use it as a tally of how many times a number was chosen, or as a way to compare the LOTTO array. If you want to see which numbers you entered
in order then you need to store them in a separate array and read back that array (such as, an array with size 6). That array would store those 6 numbers,
in the order they were given, meaning it would be very easy to read them back out in the original order as well.
The arrays are fine as they are. However, your for statement logic needs some work. Currently your array[] values are being set to the value of the variable 'numbers', however in your for loop's if statement you're looking for array[] values that are equal to 1. Well, the same thing is happening with your luck array. So, when your for loop goes through looking for 1's in these arrays, it's only going to find this to be true at array[1] and lotto[1], if you both chose 1 and rolled one. Otherwise, array[45] will = 45, and lotto[30] will = 30. See the issue here?
All you'll need to do is slightly adjust your if statement logic. I would suggest something like this:
1 2
|
if ((array[p] == lotto[p]) && array[p]!=0 && lotto[p]!=0)
match++;
|
match++
is a much better way to write
match = match +1;
Also, you do not need return statements AND break statements in your cases. And, for the love of God, get rid of the Z variable on your last For loop. :P The z and p values serve the exact same purpose.
Hope that helps.