Shopping Cart Coupon Help

Okay, So the whole program works, I am suppose to have a couponOne, that takes 50 percent off and a couponFive that takes five dollars off. The couponFive works but for some reason the couponOne keeps taking off only 5 percent. This is my Code.
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
#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>

using namespace std;
double itemValue(double item1, int quantity, double total);
double salesTax(double tax , double totalTax , double total , double item1, int quantity);
double couponCode(int codeNumber, double appliedCoupon, double totalTax, double tax, double total, double item1, int quantity);



int main()
{
	double item1 = 0;
	int quantity = 0;
	double total = 0;
	double tax = 0;
	double totalTax = 0;
	int codeNumber = 0;
	double appliedCoupon = 0;


	cout << "Thanks for shopping with us today, how many boxes of cereal were you looking to get? " << endl;
	cin >> quantity;
	cout << endl;
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	cout << "The price before tax is $ " << itemValue(item1, quantity, total) << " ." << endl;
	cout << endl;
	cout << "We are applying the standard 5 percent tax to your purchase." << endl;
	cout << endl;
	cout << "\n The total price after tax is $ " << salesTax(tax, totalTax, total,  item1, quantity) << endl;
	cout << endl;
	cout << "\n With the applied coupon your total is $ " << couponCode(codeNumber, appliedCoupon, totalTax, tax,  total, item1, quantity) << endl;
	


	system("pause");
		
	return 0;


}
double itemValue(double item1, int quantity, double total)
{
	item1 = 4.25;
	total = quantity * item1;

	return total;

	}

double salesTax(double tax, double totalTax, double total, double item1, int quantity)
{
	
	tax = 0.05;
	

	totalTax = (itemValue(item1, quantity, total) * tax) + (itemValue(item1, quantity, total));

	return totalTax;
	
}

double couponCode(int codeNumber, double appliedCoupon, double totalTax, double tax, double total, double item1, int quantity)
{
	int couponOne = 2;
	double couponFive = 5.00;
	double couponTotal;

	cout << "Please enter a coupon code that is either 1, or 5." << endl;
	cin >> codeNumber;

	if (codeNumber == 1)
	{
		couponTotal = salesTax(tax, totalTax, total, item1, quantity) / couponOne;
	}
	else if (codeNumber == 5)
		couponTotal = salesTax(tax, totalTax, total, item1, quantity) - couponFive;
	
	
	return couponTotal;
	cout << "\n With the applied coupon your total is $ " << couponTotal << endl;
}
Not sure why this is marked as solved.

Line 30: total is not passed by reference, so it is never updated. When used at lines 34 and 36, it is still 0.

Line 34: totalTax is not passed by reference, so it is never updated. When used at line 36, it is still 0.

Line 46, 55 67: I abhor passing arguments just so they can be used as local variables. If a variable is being used as a local variable, it should be declared locally.

Line 71: couponTotal is an uninitialized variable.

Line 84: If codeNumber is not 1 or 5, you're going to return garbage.

Line 85: This line will never be executed.
Last edited on
Topic archived. No new replies allowed.