This must be something simple, but its driving me mad!! Why does the code shown below not extract the string for the school? All the other bits wrok fine, except the
Code:
cin.getline( school, MAX, '\n' );
bit doesn't seem to execute
Code:
const int MAX = 30;
system( "cls" );
char first[ MAX ];
cout << "\nEnter first name : ";
cin.getline( first, MAX, '\n' );
char last[ MAX ];
cout << "\nEnter last name : ";
cin.getline( last, MAX, '\n' );
int age;
cout << "\nEnter age : ";
cin >> age;
if( cin.fail( ) )
{
cerr << "Bad input fool!" << endl;
return false;
}
cin.ignore( 80, '\n' );
char sex;
cout << "\nSex ( M or F ): ";
cin >> sex;
if( sex != 'm' && sex != 'M' && sex != 'f' && sex != 'F' )
{
cerr << "Bad input fool!" << endl;
return false;
}
char school[ MAX ];
cout << "\nEnter name of school : ";
cin.getline( school, MAX, '\n' ); //this bit aint working!
char grade;
cout << "\nEnter competitors grade :";
cin >> grade;
int heightOrWeight;
cout << ( age < 18 ? "\nEnter height ( cm ): " : "\nEnter weight ( kg ) : " );
cin >> heightOrWeight;