Bool function error

Oct 5, 2019 at 9:57am
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 ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
bool func2(string foam, string milk)
{
	string foamilk;

	cout << "Do foam and milk are in equal amounts?" << endl; 
	cin >> foamilk;
	if (foamilk == "no")
	{
		return false;
	}

	else if (foamilk == "yes")
	{
		return true;
	}
		
	
}

&& 
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
					}
Oct 5, 2019 at 10:06am
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
}
Topic archived. No new replies allowed.