Hello. I am supposed to program something like this, which prints the size and t
ID: 3540092 • Letter: H
Question
Hello. I am supposed to program something like this, which prints the size and three chosen flavors of a yogurt order:
----------------------------------------------------------
What size wold you like?
Please enter small, medium, or large: small //for example, choose small
Enter flavor 1: chocolate // choose
Enter flavor 2: DONE // When the second flavor is "DONE", the program should stop asking for the third flavor
** Order 1: small choc **
---------------------------------------------------------
But when I run it, what I got is like this:
------------------------------------------------------
What size wold you like?
Please enter small, medium, or large: small
Enter flavor 1: chocolate
Enter flavor 2: DONE
** Order 1: small choc **
** Order 1: small choc-DONE- **
---------------------------------------------------------
There is one extra line of the order description.
Here is my codes. Can someone please fix my problem?
void getYogurtFlavors(string& flavor1, string& flavor2, string& flavor3){
cout<<" ";
cout<<"Enter flavor 1: ";
cin.ignore();
getline(cin, flavor1);
cout<<"Enter flavor 2: ";
getline(cin, flavor2);
if(flavor2=="DONE"){
cout<<" ";
}
else{
cout<<"Enter Flavor 3: ";
getline(cin, flavor3);
cout<<" ";
}
}
void printOrder(const string& yogurtSize, const string& flavor1, const string& flavor2, const string& flavor3, int orderNumber){
if(flavor2=="DONE"){
cout<<"** Order "<<orderNumber<<": "<<yogurtSize+" "+flavor1.substr(0,4)<<" **"<<endl;
}
if(flavor3=="DONE"){
cout<<"** Order "<<orderNumber<<": "<<yogurtSize+" "+flavor1.substr(0,4)+"-"+flavor2.substr(0,4)<<" **"<<endl;
}
else{
cout<<"** Order "<<orderNumber<<": "<<yogurtSize+" "+flavor1.substr(0,4)+"-"+flavor2.substr(0,4)+"-"+flavor3.substr(0,4)<<" **"<<endl;
}
cout<<" ";
}