My getline function isn't working as it should. When I ask for the student's name, the code skips over reading in the name and goes right for the birthday
int main() {
cout << "Welcome to the student Database!" << endl;
char decision;
StudentDB student;
do {
cout << "Would you like to do?: 1. Add Student, 2. Update a record, 3. Delete a record, 4. Exit" << endl;
cin >> decision;
if(decision == '1' || decision == '2' || decision == '3' || decision == '4')
{
if (decision == '1'){ // add a record
string name = "", birthday = "", major = "";
cout << "Enter the student's full name." << endl;
getline(cin,name);
cout << "Enter student's birthday." << endl;
getline(cin,birthday);
cout << "Enter student's major." << endl;
getline(cin,major);
student.createRecord(name,birthday,major);
}
else if (decision == '4'){ // end program
cout << "Goodbye!" << endl;}
}
else cout << "Invalid input. Please enter a number 1-4." << endl;
}while (decision !=4);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire