when my program is compiled, the total of all the prices always equals to zero even when a product is purchased. Can someone please help me to fix what is happening. Thanks.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176`` `````` #include "stdafx.h" #include #include int main () { using namespace std; cout << "Welcome to SM Supermarket!\n"; int code = 0; string product[10]; product[0] = "Hagen Daaz"; product[1] = "Bounty Tissue"; product[2] = "Chips Ahoy Cookies"; product[3] = "Tide Laundry Detergent"; product[4] = "Lays Original Chips"; product[5] = "Sunny D Orange Juice"; product[6] = "Organic Bananas"; int priceA = 7, priceB = 10, priceC = 3, priceD = 6, priceE = 2, priceF =3, priceG = 5; int priceAtwo = 0, priceBtwo = 0, priceCtwo = 0, priceDtwo = 0, priceEtwo = 0, priceFtwo = 0, priceGtwo = 0; int amount = 0; while (code != 111){ cout << "Please enter the barcode of your item, or press '111' to check out\n"; cin >> code; if (code == 111){ goto skip_loop; } cout << "How many do you want to purchase?\n"; cin >> amount; if (code == 0123){ priceAtwo = priceA * amount; } else if (code == 0124){ priceBtwo = priceB * amount; } else if (code == 0125){ priceCtwo = priceC * amount; } else if (code == 0126){ priceDtwo = priceD * amount; } else if (code == 0127){ priceEtwo = priceE * amount; } else if (code == 0133){ priceFtwo = priceF * amount; } else if (code == 0134){ priceGtwo = priceG * amount; } } skip_loop: int coupon = 0; cout << "Please enter your coupon code, if you do not have any, please press '0'\n"; cin >> coupon; if (coupon == 051){ cout << "50% discount of 'Bounty Tissue'\n"; priceBtwo = priceBtwo / 2; } else if (coupon == 017){ cout << "\$2 off any Hagen Daaz product\n"; priceAtwo = priceAtwo - 2; } else if (coupon == 046){ cout << "\$1 off two Lays original Chips\n"; priceEtwo = priceEtwo * 2 - 1; } else if (coupon == 035){ cout << "\$1 off any Sunny D product\n"; priceFtwo = priceFtwo - 1; } else if (coupon == 0){ cout << "Your purchase is being processed\n"; } int bags = 0; cout << "How many bags would you like to purchase(1 bag/\$1 each)?\n"; cin >> bags; bags = bags * 1; int subtotal = priceAtwo + priceBtwo + priceCtwo + priceDtwo + priceEtwo + priceFtwo + priceGtwo + bags; cout << "Subtotal:\n " << subtotal; int total = subtotal * 2; cout << "\nTotal:\n " << total; int payment = 0; int pin = 0; double change = 0; double cash = 0; cout << "\nWould you like to pay with debit or cash? Press '1' for debit and '2' for cash\n"; cin >> payment; if (payment == 1){ cout << "Enter your pin number: "; cin >> pin; cout << "Approved. Your purchase is processing...\n"; } else if (payment == 2){ cout << "Please enter the amount you are paying with:\n"; cin >> cash; change = cash - total; } cout << "Thank you for your purchase. Your reciept is printing...\n"; cout << "<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>\n"; cout << " Cashier: Samantha & Madeleine\n"; cout << "\n"; cout << "\n"; cout << "--------------------------------------------------------\n"; printf("%s\n",product[0].c_str()); cout << "\$" << priceAtwo << "\n"; printf("%s\n",product[1].c_str()); cout << "\$" << priceBtwo << "\n"; printf("%s\n",product[2].c_str()); cout << "\$" << priceCtwo << "\n"; printf("%s\n",product[3].c_str()); cout << "\$" << priceDtwo << "\n"; printf("%s\n",product[4].c_str()); cout << "\$" << priceEtwo << "\n"; printf("%s\n",product[5].c_str()); cout << "\$" << priceFtwo << "\n"; printf("%s\n",product[6].c_str()); cout << "\$" << priceGtwo << "\n"; cout << "\n"; cout << "Bags"; cout << "\$" << bags; cout << "\n"; cout << "-----------------"; cout << "Subtotal: " << subtotal << "\n"; cout << "Total: " << total << "\n"; cout << "Amount Given: " << cash << "\n"; cout << "Change: " << change << "\n"; cout << "-----------------"; cout << "Thanks for shopping at SM Supermarket!"; cout << "***************************************"; cout << "Please press '1' to exit. Have a nice day!"; int exit = 0; cin >> exit; }``````
`int code = 0;` `if (code == 0123)`
if you enter 0123, it will be converted to 123, not 0123.

you should change `int code = 0;` to `string code;`
(and `#include <cstring> `)

and `if (code == 0123)` to `if (code == "0123")`
Last edited on
why cstring and not just string?
no, i meant why previous poster saying #include<cstring> and not #include<string> ?
Topic archived. No new replies allowed.