missing getline
Nov 26, 2012 at 1:30pm UTC
can anyone help me with this. the last getline in my code doesn't work. can anyone explain and improve this code?. any help will be highly appreciated.
here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#include<iostream>
using namespace std;
int main()
{
char gender;
string note, minitial;
string fname, lname, g1;
cout << "REGISTER FIRST TO ACCESS THIS PROGRAM!" << endl;
cout << "\n" << endl;
cout << "ENTER YOUR... " << endl;
cout << endl;
cout << "FIRST NAME: " ;
getline(cin, fname);
cout << endl;
cout << "MIDDLE INITIAL: " ;
getline(cin,minitial);
cout << endl;
cout << "LAST NAME: " ;
getline(cin, lname);
cout << endl;
cout << "GENDER(M or F): " ;
cin >> gender;
if (gender=='M' || gender=='m' )
g1 = "Mr." ;
else if (gender=='F' || gender=='f' )
g1 = "Ms." ;
cout << endl;
cout << "THIS IS YOUR NOTE " << g1 << fname << " " << minitial << ". " << lname << endl;
getline(cin, note);
cout << note << endl;
system("pause" );
return 0;
}
Nov 26, 2012 at 1:41pm UTC
Nov 26, 2012 at 1:57pm UTC
thank you very much coder777!!! it is now working...thank you very much ^_^
Nov 26, 2012 at 2:04pm UTC
This is an example
1 2
cin >> gender;
cin.ignore(100, '\n' );
The 100 doesn't mean that much. It ignores 100 or less new lines until there's nothing to ignore.
Nov 26, 2012 at 2:17pm UTC
Topic archived. No new replies allowed.