cout << "\nYour input was : " <<endl <<endl;
cout << "Student's name: " << name <<endl;
cout << "Student's IC number or passport number : " << icNum << endl;
cout << "Student's address : " << address <<endl;
cout << "Parent's name : " << parentName <<endl;
cout << "Parent's telephone number : " << parentTelNum << endl <<endl;
cout << "Press 1 - Re-enter particular" <<endl;
cout << "Press 2 - Confirm that the student's particular is correct" << endl;
cout << "Options : ";
cin >> choose;
}while(choose!=2);
cout << "Thank you. Info has been saved" << endl;
}
everything was right, until the end, where user have to choose 1 or 2...
when the user enters 1, the "Please Enter Student Name : "; and cout << "Student's IC number/passport number: " ; will be displayed together in one line, disabling user to enter the Student name...
how to solve?
It's because when you entered the number 1 into choose, you also entered the new-line character '\n' when you pressed return.
Reading choose only read up to the new-line character and left it in the buffer. That means the next call to getline() will read that character thinking you just typed it.
The thing to do is issue a getline() immediately after you read in your choose variable to absorm the new-line that you entered:
I always wonder why a programmer would want to clear away all previous output anyway. It's a console program and you're trying to learn. Cosmetics shouldn't be an issue at this stage.
@markjsoria: void main() is technically incorrect even though most compilers accept it. You should be using int main() {... code ... } return 0. That way the OS gets a proper return value from your code rather than a random garbage value.
I always wonder why a programmer would want to clear away all previous output anyway. It's a console program and you're trying to learn. Cosmetics shouldn't be an issue at this stage.
Also, it's against the spirit of the console. Imagine if there was a command that blanked all the paper the line printer outputted and rewound the paper feed.
In this program using getline for all inputs is very reasonable. However, sometimes you don't want to use getline for every input. if you understand the issue there are other ways of solving the problem. http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.6