Hi, i am new in c++. I am doing an assignment where I need a menu for user to select the operation.
My menu coding is as below.
int main()
{
myCarSystem b;
char ch;
string temp1, temp2;
double temp3, temp4;
while(1)
{
cout<<endl<<endl;
cout<<" My Car System Operations "<<endl;
cout<<" ----------------------------- "<<endl;
cout<<" 1. Insertion/Creation "<<endl;
cout<<" 2. In-Order Traversal "<<endl;
cout<<" 3. Removal "<<endl;
cout<<" 4. Exit "<<endl;
cout<<" Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1 : cout<<" Enter car model to be inserted : " <<endl;
fflush(stdin);
getline(cin, temp1);
cout<<"\n Enter car colour type : "<<endl;
fflush(stdin);
getline(cin, temp2);
cout<<"\n Enter car price : "<<endl;
fflush(stdin);
cin>>temp3;
cout<<"\n Enter car deposit : "<<endl;
fflush(stdin);
cin>>temp4;
b.insert(temp1, temp2, temp3, temp4);
break;
case 2 : cout<<endl;
cout<<" In-Order Traversal "<<endl;
cout<<" -------------------"<<endl;
b.print_inorder();
break;
case 3 : cout<<" Enter data to be deleted : ";
cin>>temp1;
b.remove(temp1);
break;
case 4 : system("pause");
return 0;
break;
}
}
return 0;
}
My problem is, when user is selects the operation, like example user selects 1 to enter car information, the screen will jump back to the menu and skip the input information part.
please help me to check this problem.
Thank you.
Cjjack88.