I have the following code:
Code:
#include <iostream>
using namespace std;
void get_int(int& number);
int main()
{
int n;
get_int(n);
cout << "Final value read in = " << n << endl
<< "end of demo.\n";
return 0;
}
void get_int(int& number)
{
char ans;
do
{
cout << "Enter input number:";
cin >> number;
cout << "You entered " << number
<<" Is that correct? (yes/no): ";
cin >> ans;
} while ((ans != 'Y') && (ans != 'y'));
}
If I enter a number, say 8, and then enter some random letters such as "gjh" the loop keeps going with out prompting me for more input. I can see why it would loop, but why does it not prompt me to enter another number?