1 2 3 4 5 6 7 8 9 10
|
for (int i = 0; i < 3; ++i)
{
if (playersNumbers[i] == lotteryNumbers[i]){
cout << "congrats" endl; //this line is printing every time a # matches
}
if (playersNumbers[i] != lotteryNumbers[i]){
cout << "You won nothing." << endl; //same trouble
}
}
|
I am not a professional or anything... but I can tell you that you need to rethink the logic of your code.
Lets go through this again:
You first need to see if the players numbers match a set.
Lets imagine you have this array: [123, 456, 789] for winning #s
and the player draws [123, 555, 789]
With your code as is, it would cout that they are a winner of $50,000 when they are not. (actually it would cout it 2 times along with "you won nothing" which is confusing to any avid gambler)
The player has matched the first and last places in the array, and thus we need to tell him he won the 2nd place price.
For a 1st place, 2nd place, and 3rd place you need to keep track of the amount of times a player has matched up. "if lotteryNumber[i] == playerNumber[i] { timesWon++;
}
then at the end of your code use the timeWon value to determine how many times they truly won.
--------
for your second problem:
int random_num;
random_num = 1+rand()%999;
this will give you an int between 1 and 999