maclem8223
[H]ard|Gawd
- Joined
- Oct 28, 2013
- Messages
- 1,849
I've been at this for hours and I'm sure it's something simple.
I'm just trying to figure out why the do-while loop for gender runs fine but the do-while loop for height continues infinitely. Any help would be appreciated.
I'm just trying to figure out why the do-while loop for gender runs fine but the do-while loop for height continues infinitely. Any help would be appreciated.
Code:
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
int height;
char gender;
do
{
cout << "Enter gender";
cin.get(gender);
cin.ignore(1000, '\n');
if(gender != 'M' && gender != 'm' && gender != 'F' && gender != 'f')
{
cout << "Please enter a valid gender\n";
}
}while(gender != 'M' && gender != 'm' && gender != 'F' && gender != 'f');
do
{
cout << "Enter height: ";
cin >> height;
cin.ignore(1000, '\n');
if(height < 12 || height > 20)
{
cout << "Please enter a correct height\n";
}
}while(height < 12 || height > 20);
return 0;
}
[CODE]
Last edited: