Gargbage out but no garbage in...

Ok, so I have been working on this little calculation program. I am using it to test different C++ functions and whatnot. It seems as if each section works alright, but I am getting garbage out. I entered in 10 for room height, 10 for length, 10 for width, 100 for paint coverage, and 10 for price, with the state 'GA' the program responded with 1 gallon needed, cost before discount $40 after discount $38, cost with tax &38...then I ended the sales day. The end of day report says that the one customer was from a state not listed, and the number of cans of paint needed was 1, with a cost of 38... I thought my code looked fine... but apparently something is messed up in my tax section and/or discount section. My calculation section worked just fine before the addition of discount and tax.

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <iostream>
	using namespace std;
#include <iomanip>
#include <cmath> 

void splash(void);
void getInput(void);
void doCalc(void);
void sendOutput(void);
void loop(void);
void eodr(void);

double fHeight, fWidth, fLength, fPaintSpace, fGallonCost, fGallonsNeeded, fArea;
char sFirstName[16], sLastName[16], sState[3], cSalesDay, sFirstHigh[16], sLastHigh[16];
double fCost, fTax, dDiscountPrice, fCostTax, fCostDiscount, fRedundant;
double CountGA, CountFL, CountSC, CountTN, CountAL, CostGA, CostFL, CostSC, CostTN, CostAL, TotalCount, TotalCost, CountOther, CostOther;

int main() {
	splash();
	loop();
	eodr();
	return 0;
}

void loop(void) {
  while ((cSalesDay == 'y') || (cSalesDay == 'Y')) {
		system("cls");
		getInput();
		doCalc();
		sendOutput();
	    splash();
		system("cls");
  }
return;}

void splash(void) {
	cout << "********************************************************\n";
    cout << "          Acme Paint Shop - Sales day question          \n";
	cout << "********************************************************\n\n";
	cout << "Is today a sales day (Y/N)? ";
	cin >> cSalesDay;
	system("cls");
return;}
	
void getInput(void) {
	cout << "********************************************************\n";
    cout << "              Acme Paint Shop - Input                   \n";
	cout << "********************************************************\n\n";
	cout << "Customer Name (first and last):  ";
	cin >> sFirstName >> sLastName;
	cout << "\n\nHeight:           "; // get the height of the room to be painted
	cin >> fHeight;
	cout << "\n\nWidth:            "; // get width
	cin >> fWidth;
	cout << "\n\nLength:           "; // get length
	cin >> fLength;
	cout << "\n\nGallon Coverage:  ";  // get fPaintSpace
	cin >> fPaintSpace;
	cout << "\n\nCost Per Gallon:  "; // get gallon cost
	cin >> fGallonCost;
    cout << "\n\nState:            ";
	cin >> sState;

	system("cls");

	if ((fGallonCost >= 1) && (fGallonCost <= 50)) {
		return;}
	else {
		cout << "\n\nInvalid. Please enter a number between 1 and 50: ";
		cin >> fGallonCost;
		if ((fGallonCost >= 1) && (fGallonCost <= 50)) {
				system("cls");
				return;}
		else {
				cout << "\nInvalid!!";
				system("cls");
				return;}
	}
}

void doCalc(void) {
	fArea = fHeight * fWidth;
	fGallonsNeeded = fHeight * fLength;
	fArea *= 2;
	fGallonsNeeded *= 2;
	fArea = fArea + fGallonsNeeded;
	fGallonsNeeded = ceil (fArea / fPaintSpace);
	fCost = fGallonsNeeded * fGallonCost;

	if ((sState == "ga") || (sState == "GA") || (sState == "gA") || (sState == "Ga")){ 
		CountGA = CountGA + fGallonsNeeded;}
	else if ((sState == "fl") || (sState == "FL") || (sState == "fL") || (sState == "Fl")){
		CountFL = CountFL + fGallonsNeeded;}
	else if ((sState == "sc") || (sState == "SC") || (sState == "sC") || (sState == "Sc")){
		CountSC = CountSC + fGallonsNeeded;}
	else if ((sState == "tn") || (sState == "TN") || (sState == "tN") || (sState == "Tn")){
		CountTN = CountTN + fGallonsNeeded;}
	else if ((sState == "al") || (sState == "AL") || (sState == "aL") || (sState == "Al")){
		CountAL = CountAL + fGallonsNeeded;}
	else{
		CountOther = CountOther + fGallonsNeeded;}

	if (fGallonsNeeded = 1){
		dDiscountPrice = fCost * 0.05;
		fCostDiscount = fCost - dDiscountPrice;}
	else if ((fGallonsNeeded = 2) || (fGallonsNeeded = 3)){
		dDiscountPrice = fCost * 0.1;
		fCostDiscount = fCost - dDiscountPrice;}
	else if (fGallonsNeeded = 4){
		dDiscountPrice = fCost * 0.15;
		fCostDiscount = fCost - dDiscountPrice;}
	else{
		dDiscountPrice = fCost * 0.20;
		fCostDiscount = fCost - dDiscountPrice;}

	if ((sState == "ga") || (sState == "GA") || (sState == "gA") || (sState == "Ga")){
		fTax = fCostDiscount * 0.06;
		fCostTax = fCostDiscount + fTax;}
	else if ((sState == "fl") || (sState == "FL") || (sState == "fL") || (sState == "Fl")){
		fTax = fCostDiscount * 0.04;
		fCostTax = fCostDiscount + fTax;}
	else if ((sState == "sc") || (sState == "SC") || (sState == "sC") || (sState == "Sc")){
		fTax = fCostDiscount * 0.05;
		fCostTax = fCostDiscount + fTax;}
	else if ((sState == "tn") || (sState == "TN") || (sState == "tN") || (sState == "Tn")){
		fTax = fCostDiscount * 0.05;
		fCostTax = fCostDiscount + fTax;}
	else if ((sState == "al") || (sState == "AL") || (sState == "aL") || (sState == "Al")){
		fTax = fCostDiscount * 0.02;
		fCostTax = fCostDiscount + fTax;}
	else{
		fTax = 0;
		fCostTax = fCostDiscount + fTax;}

	if ((sState == "ga") || (sState == "GA") || (sState == "gA") || (sState == "Ga")){
		CostGA = CostGA + fCostTax;}
	else if ((sState == "fl") || (sState == "FL") || (sState == "fL") || (sState == "Fl")){
		CostFL += fCostTax;}
	else if ((sState == "sc") || (sState == "SC") || (sState == "sC") || (sState == "Sc")){
		CostSC += fCostTax;}
	else if ((sState == "tn") || (sState == "TN") || (sState == "tN") || (sState == "Tn")){
		CostTN += fCostTax;}
	else if ((sState == "al") || (sState == "AL") || (sState == "aL") || (sState == "Al")){
		CostAL += fCostTax;}
	else{
		CostOther += fCostTax;}

	TotalCount += fGallonsNeeded;
	TotalCost += fCostTax;

	if (fCostTax > fRedundant){
		fRedundant = fCostTax;
		strcpy_s(sFirstHigh,sFirstName);
		strcpy_s(sLastHigh,sLastName);}

return;} // End doCalc()
	
void sendOutput(void) {
	cout << "********************************************************\n";
    cout << "      Acme Paint Shop - Single Customer Calculation     \n";
	cout << "********************************************************\n\n";
	cout << "Customer Name:            " << sFirstName << " " << sLastName << endl;
	cout << "\nNumber of Gallons Needed: " << fGallonsNeeded << endl;
	cout << "\nCost Before Discount:     $" << setprecision(2) << fixed << fCost << endl;
	cout << "\nCost After Discount:      $" << setprecision(2) << fixed << fCostDiscount << endl;
	cout << "\nCost With Tax:            $" << setprecision(2) << fixed << fCostTax << endl;
return;}

void eodr(void) {
	cout << "********************************************************\n";
    cout << "         Acme Paint Shop - End of Day Report            \n";
	cout << "********************************************************\n\n";
	cout << "State      # of Cans      Total Cost After Discount/Tax\n";
	cout << "GA           " << CountGA << "                     $" << CostGA << endl;
	cout << "FL           " << CountFL << "                     $" << CostFL << endl;
	cout << "SC           " << CountSC << "                     $" << CostSC << endl;
	cout << "TN           " << CountTN << "                     $" << CostTN << endl;
	cout << "AL           " << CountAL << "                     $" << CostAL << endl;
	cout << "Other        " << CountOther << "                     $" << CostOther << endl;
	cout << "________________________________________________________\n";
    cout << "Grand Total  " << TotalCount << "                     $" << TotalCost << endl;
	cout << "\nCustomer With Highest Total After Tax: " << sFirstHigh << sLastHigh << endl;
	cout << "Customer Total:                         $" << setprecision(2) << fixed << fRedundant << endl;
	return;
}
nvm, I figured it out by random experimentation...
what did you figure out -
I was just reading through it - and got to doCalc() and thought that those calculations seemed a bit suspicious
Well the part that was giving me the biggest problem was the taxes being applied and the number of gallons printout. The first part of doCalc() is correct. I know this because I tested it like crazy before I added the taxes and discounts and counters and so on. That was solved by switching from '=' to '=='

Now my problem is that the eodr() is throwing everything into 'Other' state category no matter which state is selected...

Code is in next reply
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <iostream>
	using namespace std;
#include <iomanip>
#include <cmath> 

void init(void);
void splash(void);
void getInput(void);
void doCalc(void);
void sendOutput(void);
void loop(void);
void eodr(void);

double fHeight, fWidth, fLength, fPaintSpace, fGallonCost, fGallonsNeeded, fArea;
char sFirstName[16], sLastName[16], sState[3], cSalesDay, sFirstHigh[16], sLastHigh[16];
double fCost, fCostTax, fCostDiscount, fRedundant;
double CountGA, CountFL, CountSC, CountTN, CountAL, CostGA, CostFL, CostSC, CostTN, CostAL, TotalCount, TotalCost, CountOther, CostOther;

int main() {
	init();
	splash();
	loop();
	eodr();
	return 0;
}

void loop(void) {
  while ((cSalesDay == 'y') || (cSalesDay == 'Y')) {
		system("cls");
		getInput();
		doCalc();
		sendOutput();
	    splash();
		system("cls");
  }
return;}

void splash(void) {
	cout << "********************************************************\n";
    cout << "          Acme Paint Shop - Sales day question          \n";
	cout << "********************************************************\n\n";
	cout << "Is today a sales day (Y/N)? ";
	cin >> cSalesDay;
	system("cls");
return;}
	
void getInput(void) {
	cout << "********************************************************\n";
    cout << "              Acme Paint Shop - Input                   \n";
	cout << "********************************************************\n\n";
	cout << "Customer Name (first and last):  ";
	cin >> sFirstName >> sLastName;
	cout << "\n\nHeight:           "; // get the height of the room to be painted
	cin >> fHeight;
	cout << "\n\nWidth:            "; // get width
	cin >> fWidth;
	cout << "\n\nLength:           "; // get length
	cin >> fLength;
	cout << "\n\nGallon Coverage:  ";  // get fPaintSpace
	cin >> fPaintSpace;
	cout << "\n\nCost Per Gallon:  "; // get gallon cost
	cin >> fGallonCost;
    cout << "\n\nState:            ";
	cin >> sState;

	system("cls");

	if ((fGallonCost >= 1) && (fGallonCost <= 50)) {
		return;}
	else {
		cout << "\n\nInvalid. Please enter a number between 1 and 50: ";
		cin >> fGallonCost;
		if ((fGallonCost >= 1) && (fGallonCost <= 50)) {
				system("cls");
				return;}
		else {
				cout << "\nInvalid!!";
				system("cls");
				return;}
	}
}

void doCalc(void) {

/* Customer Sale Calculation */

	fArea = fHeight * fWidth; // get one wall's area
	fGallonsNeeded = fHeight * fLength; // get perpendicular wall's area
	fArea *= 2; // account for two walls
	fGallonsNeeded *= 2; // account for two walls
	fArea = fArea + fGallonsNeeded; // add for total area to be painted
	fGallonsNeeded = ceil (fArea / fPaintSpace); // get number of gallons needed
	fCost = fGallonsNeeded * fGallonCost; // calculate price

/* State Gallon Counter */

	if ((sState == "ga") || (sState == "GA") || (sState == "gA") || (sState == "Ga")){ 
		CountGA = CountGA + fGallonsNeeded;}
	else if ((sState == "fl") || (sState == "FL") || (sState == "fL") || (sState == "Fl")){
		CountFL = CountFL + fGallonsNeeded;}
	else if ((sState == "sc") || (sState == "SC") || (sState == "sC") || (sState == "Sc")){
		CountSC = CountSC + fGallonsNeeded;}
	else if ((sState == "tn") || (sState == "TN") || (sState == "tN") || (sState == "Tn")){
		CountTN = CountTN + fGallonsNeeded;}
	else if ((sState == "al") || (sState == "AL") || (sState == "aL") || (sState == "Al")){
		CountAL = CountAL + fGallonsNeeded;}
	else{CountOther = CountOther + fGallonsNeeded;}

/* Discount Calculations */

	if (fGallonsNeeded == 1){fCostDiscount = fCost * 0.95;}
	else if ((fGallonsNeeded == 2) || (fGallonsNeeded == 3)){fCostDiscount = fCost * 0.90;}
	else if (fGallonsNeeded == 4){fCostDiscount = fCost * 0.85;}
	else{fCostDiscount = fCost * 0.80;}

/* STARTING THE TAX SECTION */

	if ((sState == "ga") || (sState == "GA") || (sState == "gA") || (sState == "Ga")){
		fCostTax = fCostDiscount * 1.06;}
	else if ((sState == "fl") || (sState == "FL") || (sState == "fL") || (sState == "Fl")){
		fCostTax = fCostDiscount * 1.04;}
	else if ((sState == "sc") || (sState == "SC") || (sState == "sC") || (sState == "Sc")){
		fCostTax = fCostDiscount * 1.05;}
	else if ((sState == "tn") || (sState == "TN") || (sState == "tN") || (sState == "Tn")){
		fCostTax = fCostDiscount * 1.05;}
	else if ((sState == "al") || (sState == "AL") || (sState == "aL") || (sState == "Al")){
		fCostTax = fCostDiscount * 1.02;}
	else{fCostTax = fCostDiscount * 1.00;}

/* Cost by State Counter */

	if ((sState == "ga") || (sState == "GA") || (sState == "gA") || (sState == "Ga")){
		CostGA = CostGA + fCostTax;}
	else if ((sState == "fl") || (sState == "FL") || (sState == "fL") || (sState == "Fl")){
		CostFL = CostFL + fCostTax;}
	else if ((sState == "sc") || (sState == "SC") || (sState == "sC") || (sState == "Sc")){
		CostSC = CostSC + fCostTax;}
	else if ((sState == "tn") || (sState == "TN") || (sState == "tN") || (sState == "Tn")){
		CostTN = CostTN + fCostTax;}
	else if ((sState == "al") || (sState == "AL") || (sState == "aL") || (sState == "Al")){
		CostAL = CostAL + fCostTax;}
	else{CostOther = CostOther + fCostTax;}

/* Keeping track of Totals */

	TotalCount += fGallonsNeeded;
	TotalCost += fCostTax;

	if (fCostTax > fRedundant){
		fRedundant = fCostTax;
		strcpy_s(sFirstHigh,sFirstName);
		strcpy_s(sLastHigh,sLastName);}

return;} // End doCalc()
	
void sendOutput(void) {
	cout << "********************************************************\n";
    cout << "      Acme Paint Shop - Single Customer Calculation     \n";
	cout << "********************************************************\n\n";
	cout << "Customer Name:            " << sFirstName << " " << sLastName << endl;
	cout << "\nNumber of Gallons Needed: " << fGallonsNeeded << endl;
	cout << "\nCost Before Discount:     $" << setprecision(2) << fixed << fCost << endl;
	cout << "\nCost After Discount:      $" << setprecision(2) << fixed << fCostDiscount << endl;
	cout << "\nCost With Tax:            $" << setprecision(2) << fixed << fCostTax << endl;
return;}

void eodr(void) {
	cout << "********************************************************\n";
    cout << "         Acme Paint Shop - End of Day Report            \n";
	cout << "********************************************************\n\n";
	cout << "State      # of Cans      Total Cost After Discount/Tax\n";
	cout << "GA           " << setprecision(0) << fixed << CountGA << "                     $" << CostGA << endl;
	cout << "FL           " << setprecision(0) << fixed << CountFL << "                     $" << CostFL << endl;
	cout << "SC           " << setprecision(0) << fixed << CountSC << "                     $" << CostSC << endl;
	cout << "TN           " << setprecision(0) << fixed << CountTN << "                     $" << CostTN << endl;
	cout << "AL           " << setprecision(0) << fixed << CountAL << "                     $" << CostAL << endl;
	cout << "Other        " << setprecision(0) << fixed << CountOther << "                     $" << CostOther << endl;
	cout << "________________________________________________________\n";
    cout << "Grand Total  " << TotalCount << "                     $" << TotalCost << endl;
	cout << "\nCustomer With Highest Total After Tax: " << sFirstHigh << sLastHigh << endl;
	cout << "Customer Total:                         $" << setprecision(2) << fixed << fRedundant << endl;
	return;
}
void init(void) {
	
	fHeight = 0.0; fWidth = 0.0; fLength = 0.0; fPaintSpace = 0.0; fGallonCost = 0.0;
	fGallonsNeeded = 0.0; fArea = 0.0; fCost = 0.0;
	fCostTax = 0.0; fCostDiscount = 0.0; fRedundant = 0.0; CountGA = 0.0; CountFL = 0.0;
	CountSC = 0.0; CountTN = 0.0; CountAL = 0.0; CostGA = 0.0; CostFL = 0.0; CostSC = 0.0;
	CostTN = 0.0; CostAL = 0.0; TotalCount = 0.0; TotalCost = 0.0; CountOther = 0.0; CostOther = 0.0;
}
It was the use of the fGallonsNeeded that threw me.
I thought why give a variable a name like that + then use it as an area calculation (if only briefly).
Topic archived. No new replies allowed.