{
int array [20];
int num;
int count;
cout << "How many whole numbers would you like to enter (max 20)?" << endl;
cin >> num;
do
{
if (num <= 20)
cout << "Enter " << num << " numbers. " << endl;
else
cout << "Invalid. Enter another amount." << endl;
cin >> num;
} while (num != false);
}
Right now if I insert a higher number than 20 it goes to invalid. When I enter a letter it just starts looping negative numbers infinitely without a pause. Any ideas of what I'm doing wrong?
It will loop infinitely even if you input 3. If you move lines 6 and 7 inside the do...while, it will repeat the cycle only until you type 0 or not an integer. You might want to put a sensible condition for exit. Also, you might want to use unsigned int, or put a check not to ask "Enter -3 numbers".