Getting $0 for tax in a program

I... am gonna murder this computer.

Okay. So when I enter the sample values of "50, 25, and 35" for beef, chicken, and vegan meals respectively, I get all the right results according to the assignment, including a Room Tax of $13.00. But when I use the sample values of "0, 0, and 25" for beef, chicken, and vegan meals respectively, this dirty liar of a program tells me that the tax is $0. Zero! ARRRG! What am I doing wrong!? I am up to my wits end with this crap!

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
	// This program will calculate the total bill for customers of the XXXX Company.

	// Naming values and constants.
	const double BEEF_MEAL = 12.95; // Cost of a single beef meal.
	const double CHICKEN_MEAL = 10.95; // Cost of a single chicken meal.
	const double VEGAN_MEAL = 8.95; // Cost of a single vegan meal.
	int beefMealAmount; // Amount of beef meals the customer orders.
	int chickenMealAmount; // Amount of chicken meals the customer orders.
	int veganMealAmount; // Amount of vegan meals the customer orders.
	const int ROOM1 = 250; // Cost of Room 1, which seats 200 people.
	const int ROOM2 = 200; // Cost of Room 2, which seats 150 people.
	const int ROOM3 = 100; // Cost of Room 3, which seats 100 people.
	const int ROOM4 = 50; // Cost of room 4, which seats 30 people.

	// Input from customer.
	cout << "Enter number of beef meals: ";
	cin >> beefMealAmount;
	if(beefMealAmount < 0)
	{
		cout << "Invalid data. ";
		return 1;
	}
	else if(beefMealAmount >= 0)
	{
	cout << "Enter number of chicken meals: ";
	cin >> chickenMealAmount;
	}
	if(chickenMealAmount < 0)
	{
	cout << "Invalid data. ";
		return 1;
	}
	else if(chickenMealAmount >= 0)
	{
	cout << "Enter number of vegan meals: ";
	cin >> veganMealAmount;
	}
	if(veganMealAmount < 0)
	{
		cout << "Invalid data. ";
		return 1;
	}
	else if(veganMealAmount >= 0)
	{
	}

	// Bill calculations.
	cout.setf (ios::fixed | ios::showpoint);
	cout.precision (2);
	int totalPeople = (beefMealAmount + chickenMealAmount + veganMealAmount); // Total number of guests.
	const double MEAL_COSTS = (BEEF_MEAL * beefMealAmount) +  (CHICKEN_MEAL * chickenMealAmount) + (VEGAN_MEAL * veganMealAmount); // Total costs of all meals.
	const double GRATUITY = MEAL_COSTS / 100 * 18; // Gratuity for amount spent on meals.
	// Below are the calculations for room cost.
	if(totalPeople > 200)
	{
		cout << "There is no room large enough. ";
		return 1;
	}
	int ROOMCOST = 0;
	if(totalPeople >= 1 && totalPeople <= 30)
	{
		ROOMCOST = ROOM4;
	}
	else if(totalPeople >= 31 && totalPeople <= 100)
	{
		ROOMCOST = ROOM3;
	}
	else if(totalPeople >= 101 && totalPeople <= 150)
	{
		ROOMCOST = ROOM2;
	}
	else if(totalPeople >= 151 && totalPeople <= 200)
	{
		ROOMCOST = ROOM1;
	}
	const double STATE_TAX = ROOMCOST / 100 * 6.5;

	// Section for everything the program will display.
	cout.setf (ios::fixed | ios::showpoint);
	cout.precision (2);
	cout << " " << endl;
	cout << "Caswell Caterers by Jesse Sails" << endl;
	cout << " " << endl;
	cout << setw (40) << left << "Number in party:" << totalPeople << endl;
	cout << setw (60) << left << "Room Cost:" << "$" << ROOMCOST << endl;
	cout << setw (60) << left << "Room Tax:" << "$" << STATE_TAX << endl;
	if(beefMealAmount > 0)
	{
		cout << setw (40) << left << "Number of beef dinners:" << beefMealAmount << endl;
		cout << setw (60) << left << "Cost of beef dinners:" << "$" << BEEF_MEAL * beefMealAmount << endl;
	}
	if(chickenMealAmount > 0)
	{
		cout << setw (40) << left << "Number of chicken dinners:" << chickenMealAmount << endl;
		cout << setw (60) << left << "Cost of chicken dinners:" << "$" << CHICKEN_MEAL * chickenMealAmount << endl;
	}
	if(veganMealAmount > 0)
	{
		cout << setw (40) << left << "Number of vegan dinners:" << veganMealAmount << endl;
		cout << setw (60) << left << "Cost of vegan dinners:" << "$" << VEGAN_MEAL * veganMealAmount << endl;
	}
	cout << setw (60) << left << "Food Gratuity:" << "$" << GRATUITY << endl;
	cout << "---------------------------------------------------------------------------" << endl;
	cout << setw (60) << left << "Total:" << "$" << MEAL_COSTS + ROOMCOST + STATE_TAX + GRATUITY << endl;
	cout << " " << endl;
return 0;
}


I'm sorry. I just need to vent. Programming is SO frustrating. There's always SOMETHING at the very, very end. I've run into about 10 somethings in the last hour. "Just this one, and it'll be perfect." But NOOOOO. There's always one more stupid arbitrary thing that I've done wrong somehow. I just wanna go to bed already! I'm... I'm so tired. D: *sobs*

Okay. I tried changing the room values all from const ints to constant doubles, but that didn't fix the problem either. Can someone pretty please tell me what I'm doing wrong before my fist becomes one with the laptop screen? Any and all help appreciated.
Last edited on
Hey, just change line 82, either of these should work if my memory serves me:

const double STATE_TAX = ROOMCOST * 6.5/ 100;

const double STATE_TAX = ROOMCOST * .065;
Omigosh omigosh omigoooosh!

How!? How did you do that? How did you know that would work? How was your percentage-calculating equation any different from mine in the eyes of the program? o.O Are you a magician or something? You're amazing!
It's probably just because I go out to eat too often :P

Glad you got it working.
The real reason is the 'ROOMCOST' is an integer. If ROOMCOST < 100 and you divide it by 100 then the result is 0. The decimal places are omitted

You can to the following:

const double STATE_TAX = double(ROOMCOST) / 100 * 6.5;

That should calculate that 6.5 precent of the room cost.

Take care that there's no other integer division within your code!
Topic archived. No new replies allowed.