Need some advice
Mar 3, 2010 at 9:39pm UTC
Sorry Here is my new post with code tags. New to the site.
I am working on a school assignment that is a convenience store. I have posted the assignment below for you to better understand:
This program is will be a simple simulation of a convenience store, though with only a few products from which to choose. Your store should simulate for the user the functionality of a real-world convenience store: different products to choose from, different prices for different products, a display of the total amount owed, a display of the amount paid (when the player has paid), and a display of the amount to refund (should your customer overpay). Do NOT let your customer "leave" your store until she/he provides adequate payment for the items selected. Upon the completion of a transaction, you should print a "receipt" of the transaction, including all of the details available about the transaction (items purchases and quantities, amount paid, amount in change, etc.).
I have provided my coding so far below. The problem I am having is starting on the receipt coding. I am stuck on what to do. Any help would be greatly appreciated.
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
#include <iostream>
#include "CinReader.h"
using namespace std;
CinReader reader;
int main()
{
int soda = 0;
soda = 200;
int jerky = 0;
jerky = 100;
int toiletPaper = 0;
toiletPaper = 300;
int beer = 0;
beer = 800;
int cigarettes = 0;
cigarettes = 600;
int customerChoice = 0;
int moneyOwed = 0;
int customerMoney = 0;
customerMoney = 3000;
int moneyPaid = 0;
bool checkOut = false ;
cout << " ## ## ######## ## ###### ####### ## ## ########" << endl;
cout << " ## ## ## ## ## ## ## ## ## ### ### ## " << endl;
cout << " ## ## ## ## ## ## ## ## #### #### ## " << endl;
cout << " ## ## ## ###### ## ## ## ## ## ### ## ###### " << endl;
cout << " ## ## ## ## ## ## ## ## ## ## ## " << endl;
cout << " ## ## ## ## ## ## ## ## ## ## ## ## " << endl;
cout << " ### ### ######## ######## ###### ####### ## ## ########" << endl << endl;
cout << " *********************************" << endl;
cout << " ***TO CHRIS'S CONVENIENCE STORE***" << endl;
cout << " *********************************" << endl << endl;
cout << " $$$$ YOU HAVE " << customerMoney << " PENNIES TO SPEND $$$$" << endl << endl;
cout << " ??? WHAT WOULD YOU LIKE TO PURCHASE TODAY ??? " << endl << endl;
do
{
cout << " ITEMS: PRICE:" << endl << endl;
cout << " 1. Soda.............................200 Pennies" << endl;
cout << " 2. Jerky............................100 Pennies " << endl;
cout << " 3. Toilet Paper.....................300 Pennies" << endl;
cout << " 4. Beer.............................800 Pennies" << endl;
cout << " 5. Cigarettes.......................600 Pennies" << endl;
cout << " [0] ................Checkout...................." << endl << endl;
cout << "MAKE YOUR SELECTION" << endl << endl;
customerChoice = reader.readInt();
if (customerChoice > 5)
cout << endl << "You obviously do not know how to count. Pick items 1 through 5." << endl << endl;
switch (customerChoice)
{
case 1:
if (moneyOwed >= customerMoney)
// compiler error when line is split into two for some odd reason
cout << "!!!YOU HAVE NO MORE MONEY, YOU WILL NOT BE ALLOWED!!!" << endl << "!!!ANY MORE TRANSACTIONS, PLEASE CHECKOUT!!!" << endl;
else
moneyOwed = moneyOwed + soda;
cout << endl << "You have choosen a soda." << endl << endl;
cout << "You now owe me " << moneyOwed << " pennies" << endl;
cout << "Would you like to buy anything else!!!" << endl << endl << endl << endl;
break ;
case 2:
if (moneyOwed >= customerMoney)
// compiler error when line is split into two for some odd reason
cout << "!!!YOU HAVE NO MORE MONEY, YOU WILL NOT BE ALLOWED!!!" << endl << "!!!ANY MORE TRANSACTIONS, PLEASE CHECKOUT!!!" << endl;
else
moneyOwed = moneyOwed + jerky;
cout << endl << "You have bought some Jerky." << endl << endl;
cout << "You now owe me " << moneyOwed << " pennies" << endl;
cout << "Would you like to buy anything else!!!" << endl << endl << endl << endl;
break ;
case 3:
if (moneyOwed >= customerMoney)
// compiler error when line is split into two for some odd reason
cout << "!!!YOU HAVE NO MORE MONEY, YOU WILL NOT BE ALLOWED!!!" << endl << "!!!ANY MORE TRANSACTIONS, PLEASE CHECKOUT!!!" << endl;
else
moneyOwed = moneyOwed + toiletPaper;
cout << endl << "You have bought Toilet Paper." << endl << endl;
cout << "You now owe me " << moneyOwed << " pennies" << endl;
cout << "Would you like to buy anything else!!!" << endl << endl << endl << endl;
break ;
case 4:
if (moneyOwed >= customerMoney)
// compiler error when line is split into two for some odd reason
cout << "!!!YOU HAVE NO MORE MONEY, YOU WILL NOT BE ALLOWED!!!" << endl << "!!!ANY MORE TRANSACTIONS, PLEASE CHECKOUT!!!" << endl;
else
moneyOwed = moneyOwed + beer;
cout << endl << "You have bought Beer." << endl << endl;
cout << "You now owe me " << moneyOwed << " pennies" << endl;
cout << "Would you like to buy anything else!!!" << endl << endl << endl << endl;
break ;
case 5:
if (moneyOwed >= customerMoney)
// compiler error when line is split into two for some odd reason
cout << "!!!YOU HAVE NO MORE MONEY, YOU WILL NOT BE ALLOWED!!!" << endl << "!!!ANY MORE TRANSACTIONS, PLEASE CHECKOUT!!!" << endl;
else
moneyOwed = moneyOwed + cigarettes;
cout << endl << "You have bought some Cigarettes." << endl << endl;
cout << "You now owe me " << moneyOwed << " pennies" << endl;
cout << "Would you like to buy anything else!!!" << endl << endl << endl << endl;
break ;
case 0:
cout << "You owe me " << moneyOwed << " pennies" << endl;
cout << "Enter penny amount to pay..." << endl;
moneyPaid = reader.readInt();
moneyOwed = moneyOwed - moneyPaid;
if (moneyOwed == moneyPaid)
//cout << "Thank you come again" << endl;
checkOut = true ;
else
cout << " THATS NOT ENOUGH PARTNER, DON'T MAKE ME GET MY SHOTTIE " << endl;
cout << " YOU STILL OWE ME " << moneyOwed << " PENNIES" << endl;
break ;
}
} while (checkOut == false );
return 0;
}
Last edited on Mar 4, 2010 at 12:27am UTC
Mar 3, 2010 at 11:52pm UTC
Please use code tags & indentation.
As for a receipt, I would start writing the information as they choose each item and just print it at the end rather than trying to create it all at once.
Mar 4, 2010 at 1:46am UTC
could you elaborate on this. I have worked with print functions, but how would I keep track of everything they purchase.
Topic archived. No new replies allowed.