I am trying to get the function to check if the user input is between 1 and 40. If it is not, it should cout "Invalid number input. please select again.
But whenever I try to enter a number less than 1 or greater than 40 it displays the proper cout statement, but it inputs a 00 into those element slots of the array.
void getLottoPicks(int ticket[], int size)
{
int num = 0;
clearTicket(ticket);
cout << "Choose 7 numbers between 1 and 40 and enter them 1 at a time: ";
cout << endl;
for (int x = 0; x < size; x++)
{
cin >> num;
if (num > 1 && num < 40)
{
while (!NoDuplicates(ticket, num, size))
{
cout << "Cannot have the same number twice, please reenter: " << endl;
cin >> num;
}
ticket[x] = num;
}
else
cout << "Invalid Selection, Please choose again." << endl;
}
}
I figured it out. The error was in my else statement. I was only displaying the message Invalid Selection, rather than displaying the message then asking the user again to input a valid number.