### 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.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586`` ``````#include #include #include #include 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.