Could you please help me determining what is wrong in my code again? Every time you select a case, for example you selected "1" which is "NBA Player", and you are asked who is your favorite player, the program ends as soon as you type your answer. I think the problem is in my getline statement but I can't really identify it.
#include<iostream> #include<conio.h> #include<string> using namespace std; int main() { int choice; string nbaPlayer; string tele; string food; string subject; string x; cout << "This program determines your favorites.\n\n"; cout << "Please select the number of your corresponding choice."; cout << "\n1. NBA Player"; cout << "\n2. Teleserye"; cout << "\n3. Food"; cout << "\n4. Subject"; cout << "\n5. Exit"; cin >> choice; switch (choice) { case 1: cout << "You have chosen NBA Player.\n"; cout << "Please enter your favorite NBA Player. \n"; getline(cin, nbaPlayer); cout << "Your favorite NBA player is " << nbaPlayer; break; case 2: cout << "You have chosen Teleserye.\n"; cout << "Please enter your favorite teleserye. \n"; getline(cin, tele); cout << "Your favorite teleserye is " << tele; break; case 3: cout << "You have chosen food.\n"; cout << "Please enter your favorite food. \n"; getline(cin, food); cout << "Your favorite food is " << food; break; case 4: cout << "You have chosen subject.\n"; cout << "Please enter your favorite subject. \n"; getline(cin, subject); cout << "Your favorite subject is " << subject; break; case 5: cout << "You chose to exit.\n"; break; default: cout <<"\nInvalid input"; } getch(); }