matchCounter is not modifying main's match variable, but only it's own local copy of it. You could pass a reference by changing matchCounter to
void matchCounter(int *lottery, int *user, int &match)
Better yet, you could have matchCounter return the calculated value directly without having to pass in a variable (which is a little strange when you think about it).
1 2 3 4 5
int matchCounter(int *lottery, int *user) {
int match = 0;
...
return match;
}
Also note that your random digits will never be 0 since you are always adding 1. It should just be rand() % 10.
You have an array why not use this fact instead of hard coding the array elements?
By the way you really should be passing the size of the array into the functions that require it (in for() loops) instead of using the "magic numbers".
Thank you TPB, I got my code up and running, although as JLB pointed out it could be better!
JLB, it needs be in the same spot in the array to match, which I think my code has. I agree that it shouldnt be hardcoded and will change it. Obviously I'm new to this and I wanted to rule out errors as much as I can and will be changing that. I'll also add a constant int that is set to 5 and use that for my for loops and declaring array sizes. Is that what you mean by passing the size into the functions?
zero is a special case.
int x[10] = {0}; //this will initialize all to zero. it does not work for nonzero values.
yes, you don't want to 'know' that everything is 5.
if its globally 5 for the whole program, as in your case, its OK to have a global scoped constant value. Then if you change it to 6 in a single place, it fixes everything and your program grew to handle a bigger problem with no real effort. It is a lot harder to change some, but not all, of the 5s in a program to 6, then later to 10, etc ... if you change an unrelated 5 to 6, thats a bug, if you miss one, its a bug, etc. If you change one thing... many potential issues clear up (not impressive on a 1/2 page program, but imaging changing about 75% of the 5s in a 20000 line program to 6s....