I want to make a lottery generator and compare both of them together to see if the user is a winner or not. I think I'm on the right track but I'm getting an error message in from my compiler "error C2440: '=' : cannot convert from 'void' to 'int'". Can anyone please help? thanks.
It looks like the function getUserNumber is declared to return a 'void' type - that is, no value. It must be declared to return an 'int' in this case, since that is the type of data you want to store to userNum.
Edit: If you want to return more than one number, consider returning an array instead of just one int. This should be done with a return statement.
1 Number Example:
1 2 3 4 5 6 7
...
int myFunc( )
{
int myNum = 5;
return myNum;
}
...
(The above is only meant as an example, keep in mind it is only returning the address of a temporary variable - for your situation it looks like you'll return the address of the user variable, since that is what's being modified.)
Thank you for your quick reply. I changed all the voids to int and I get more errors.
warning C4101: 'lottery' : unreferenced local variable
warning C4244: 'initializing' : conversion from 'time_t' to 'unsigned int', possible loss of data
warning C4101: 'userNum' : unreferenced local variable
error C4716: 'randomNumber' : must return a value
error C4716: 'getUserNumber' : must return a value
I also noticed that you don't need to return anything with getUserNumbers(), since you are passing it the address of the thing you want to modify (and are doing so with cin). This changes the contents at that address, so you should then (after the function call), be able to get those values by iterating over user[...].
That function can be done without returning a value, in this case.
My observation was late, for that I apologize. As I stated in my late followup, you don't need to return a value to anybody for getUserNumbers( ..., ... ) since you are passing it the array - and this the address of the data you want to edit (the user numbers). Use a for loop to iterate over user[...] after the function call and you should be able to access he numbers inputted.
Edit: Remember to not try and store anything with something = getUserNumbers(..., ...); if you're return type is void - it should just be the function call by itself.
I think this should work for what you are trying to do.
Building on Desh's post, getUserNumber can be void instead of type int. This is because arrays are passed to functions by reference, not by value. Consequently you can remove "return user", since a function of type void does not return anything. This will allow you to remove userNum from the main function as well. To print out the array just add a for loop, as Desh stated.
I should have caught this early, so I apologize. In line 28 you are assigning an int array (the return value from randomNumber) to an int (lotteryNum). This is what is causing the -858993460. To fix this, change randomNumber from type int to type void and remove its return value. Also remove line 29 which prints out lotteryNum. That is not needed; what you are printing out in the randomNumber function will suffice. You can also remove int lotteryNum and int lottery[SIZE] altogether. It should now run properly.
Alternatively, you could remove int lottery from randomNumber and place it in main. Then pass lottery to randomNumber. This would allow you to keep randomNumber and getUserNumber as void. Then you can replace your while loop with a for loop that compares each element of lottery with each element of user and checks to see if there is a match or not.