main()
{
int n; /* number of values entered */
cout << "How many values? (1..10) -> ";
cin >> n;
cin.ignore(SHRT_MAX, '\n');
/* control number of value entered by the user */
while (n<1||n>10)
{
cout << "\nInvalid input. Try again (1..10) -> ";
cin >> n;
cin.ignore(SHRT_MAX, '\n');
}
}
Thus so far I have got the input will be within the range 1 to 10 and if the user will type in any value with a fraction part the program cut it off.
But if the user type in a letter the program crash!!!
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.