cout << "Enter 10 numbers: " << endl;
for (i=0; i<=9; i++)
{
if (x<=10)
{
cout << "Number " << x << ": ";
cin >> input[i];
if (!cin)
{
cin.clear();
cout << "Error: You Must Enter A Number. " << endl;
cin >> input[i];
}
x++;
}
elseif (x==10)
{
break;
}
}
I tried that out but it would repeat the error for all 10 input, instead of giving an error for that 1st one. I want to give an error for that one time they enter a letter, then have the program tell them to redo their input, then have it proceed to the next number "number 2: " So anyone have any ideas of what I should try?
Try this, we need to read and ignore the incorrect input
while (!cin)
{
char str[10];
cin.clear();
cout << "Error: You Must Enter A Number. " << endl;
cin >> str; // Ignore the incorrect input
cin >> input[i];
}