I'm new to C++ and need help. I need to write a program to simulate Lottery. need an array named winningDigits with 5 randomly generated numbers(0-9). an array named player where i ask user to input 5 digit numbers (0-9). need to compare the two arrays and display how many digits match. for example, if
when i run it, it doesn't compare and display numbers that are matched.
in a practice run output is:
Enter your Lottery Pick#1: 8
Enter your Lottery Pick#2: 3
Enter your Lottery Pick#3: 5
Enter your Lottery Pick#4: 2
Enter your Lottery Pick#5: 7
============================
Winning Lottery Numbers:
7 2 5 9 1 0
============================
You matched 1987281253 Press any key to continue.....
I don't know where the 0 came from in winning number list or the numbers 1987281253????
It's not comparing players numbers with winning numbers and displaying which elements match
number is uninitialized here - do you really need 3 separate variables to keep track of the '5'?
cout << "\n\tYou matched " << arrayMatch[number];
With number = 5, this outputs the 6th element of the (0 based) arrayMatch, so it's just going to be gibberish.
Honestly, your understanding of how arrays work looks like it could use some work. I would spend some time going back to learn the basics of arrays - what do the brackets mean when declaring an array vs what they mean when working with an existing array, how indices work, what the max index you can safely use for any given array is, etc.
you're right i am confused. this is my first class into programming and i am not being given anything other than read the book and google for the answer. i could use lectures/videos on subject. any ideas?
there are probably numerous videos if you prefer as well. Go through a few of these, get a firm understanding of arrays, then give this another shot. Understanding pointers is also very important, but if your class hasn't gotten there yet, don't worry about it yet.