Saturday, 7 September 2013

How can I rearrange this so input Ctrl-z(end of file signal) breaks loop while still testing for valid inputs in c++

How can I rearrange this so input Ctrl-z(end of file signal) breaks loop
while still testing for valid inputs in c++

==================================================================================
I have two problems here.
1. When I enter a valid input(positive number) it is successfully put into
the vector but then returns down to the next blank line waiting for
another input when it should just ask the same question again. And it
does. just only every other input Why is it stopping on a blank line like
that? 2. How can I rearrange this so Ctrl-z will signal end of file
instead of failing as
an invalid input?
do
{
cout << "\nPlease enter a homework score<'Ctrl-z' when done>: ";
cin >> value;
while(cin.fail() || value < ZERO)
{
cout << "not a valid positive numerical value. try again. \n";
cin.clear();
cin.ignore(numeric_limits<int>::max(),'\n');
cout << "\nplease enter a valid homework score<'Ctrl-z' when
done>: ";
cin >> value;
}
assignmentScore.push_back(value);
}while(cin >> value);

No comments:

Post a Comment