J
JR
Hey all,
I have read part seven of the FAQ and searched for an answer but can
not seem to find one.
I am trying to do the all too common verify the data type with CIN.
The code from the FAQ looks like this:
#include <iostream>
int main()
{
std::cout << "Enter a number, or -1 to quit: ";
int i = 0;
while (std::cin >> i) { // GOOD FORM
if (i == -1) break;
std::cout << "You entered " << i << '\n';
}
}
This works well except that I do not want to exit the loop unless a
valid input is entered. So if I enter an 'a' I want to stay in the
loop to allow for another chance at input not exit the loop. Can
someone please provide a modified version of this code that will allow
this?
Thanks,
James
I have read part seven of the FAQ and searched for an answer but can
not seem to find one.
I am trying to do the all too common verify the data type with CIN.
The code from the FAQ looks like this:
#include <iostream>
int main()
{
std::cout << "Enter a number, or -1 to quit: ";
int i = 0;
while (std::cin >> i) { // GOOD FORM
if (i == -1) break;
std::cout << "You entered " << i << '\n';
}
}
This works well except that I do not want to exit the loop unless a
valid input is entered. So if I enter an 'a' I want to stay in the
loop to allow for another chance at input not exit the loop. Can
someone please provide a modified version of this code that will allow
this?
Thanks,
James