I couldn't find out what is the error in my code. When I enter no as an input it asks again "Do foam and milk are in equal amounts ?" when I enter no again the program prompts the correct output but i'm confused about why does it ask twice ?
bool func2(string foam, string milk)
{
string foamilk;
cout << "Do foam and milk are in equal amounts?" << endl;
cin >> foamilk;
if (foamilk == "no")
{
returnfalse;
}
elseif (foamilk == "yes")
{
returntrue;
}
}
&&
if (func2(foam, milk))
{
milkandfoam == true;
cout << " Your order is ready " << name << "! What you want is a cappucino. Enjoy!" << endl; // cappucino
}
if (func2(foam, milk) == false)
{
milkandfoam == false;
cout << " Your order is ready " << name << "! What you want is a latte. Enjoy!" << endl; //latte
}
1. You need to make func2() return something if the answer is something other than "yes" or "no".
As it stands, you get randomness.
> 23 milkandfoam == true;
> 28 milkandfoam == false;
Using == where you meant =
TBH, do
1 2 3 4 5 6
milkandfoam = func2(foam, milk);
if ( milkandfoam ) {
cout << " Your order is ready " << name << "! What you want is a cappucino. Enjoy!" << endl; // cappucino
} else {
cout << " Your order is ready " << name << "! What you want is a latte. Enjoy!" << endl; //latte
}