Calculate tip for restaraunt bill and how much each person should pay.

I need to write a program that prompts the user for how many people are eating at a restaurant and how much the bill is, and then calculates how much a 16% tip would be, a 20% tip, and how much each person should pay if everyone is to pay the same amount. I need to set up the program so that it outputs information in a list format with information in two columns with dots seperating the columns. Like this:

Number of people eating.....................5
Bill amount..................................$20.00

Here is what I've got so far:

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
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()

{
	double peopleEating;
	double billAmount;
	double exit;
	cout << " This program will calculate how much the tip should be and how much each person should pay after eating at a restaurant. " << endl;
	cout << " How many people are eating? " << endl;
	cin >> peopleEating;
	cout << " How much was the bill? " << endl;
	cin >> billAmount;
	cout << setfill('.');
	cout << left;
	cout << "Number of people eating";
	cout << cout.unsetf(ios::left);
	cout << right;
	cout << peopleEating;
	cout << cout.unsetf(ios::right);
	cout << " Type exit to exit. " << endl;
	cin >> exit;
}


When I compile it I get two errors that both read

"error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)"

I haven't even tried to do the math yet. I think if I can figure out this list part the rest will be easy.

What am I doing wrong and how can I fix it? Many thanks in advance for any assistance.
Last edited on
Hmmm. I can't see what line it's on so I can't say for sure. But I believe it's because you can't pass setf and unsetf. You call them straight up.
cout << cout.unsetf(bla); // wrong

cout.unsetf(bla); // right
Last edited on
Ahh.. Ok so I deleted cout << and the program will run, and when it runs it will ask me how many people are eating and how much was the bill, so I put in 5 for both and the program will say

Number of people eating5 Type exit to exit.

How do I get the column format?
I'm no expert on iomanip. I personally prefer plain unformatted (in terms of spacing at least) output.
Last edited on
If I put in 20.00 when it asks "How much is the bill?", in the list it makes afterwards it only says "Amount on bill: 20" How do I make it say 20.00?
I figured it out. Here it is if anyone would like to see how to do it:

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()

{
	double peopleEating;
	double billAmount;
	int exit;
	cout << "This program will calculate how much the tip should be and how much each person should pay after eating at a restaurant. " << endl;
	cout << " " << endl;
	cout << "How many people are eating? " << endl;
	cin >> peopleEating;
	cout << " " << endl;
	cout << "How much was the bill? (Do not insert a dollar sign)" << endl;
	cin >> billAmount;
	cout << " " << endl;
	cout << setfill ('.') << left << setw(50) << "Number of people eating: "
		 << right << "   " << peopleEating << endl;
	cout << fixed << showpoint;
	cout << setprecision(2)
		 << setfill ('.') << left << setw(50) << "Total bill amount: "
		 << right << " $ " << billAmount << endl;
	cout << " " << endl;
	cout << setfill ('.') << left << setw(50) << "16% tip: "
		 << right << " $ " << 0.16 * billAmount << endl;
	cout << setfill ('.') << left << setw(50) << "Total with 16% tip: "
		 << right << " $ " << billAmount + (0.16 * billAmount) << endl;
	cout << setfill ('.') << left << setw(50) << "Amount each person should pay with 16% tip: "
		 << right << " $ " << (billAmount + (0.16 * billAmount)) / peopleEating << endl;
	cout << " " << endl;
	cout << setfill ('.') << left << setw(50) << "20% tip: "
		 << right << " $ " << 0.2 * billAmount << endl;
	cout << setfill ('.') << left << setw(50) << "Total with 20% tip: "
		 << right << " $ " << billAmount + (0.2 * billAmount) << endl;
	cout << setfill ('.') << left << setw(50) << "Amount each person should pay with 20% tip: "
		 << right << " $ " << (billAmount + (0.2 * billAmount)) / peopleEating << endl;
	cout << " " << endl;
	cout << "Type exit to exit. " << endl;
	cin >> exit;
}


Thank you tummychow for the help.
Topic archived. No new replies allowed.