Mar 3, 2010 at 11:25pm UTC
Sorry last post was kinda confusing. Here is the coding for the whole program. Its a school assignment of a convenience store. I switched the code to ==, but still primary expression error in the same place. I underlined the code where i'm getting an error. says I need ; before my else statement. Don't get it.
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 below 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:31am UTC
Mar 3, 2010 at 11:27pm UTC
What is the error? I believe you should use ==, which is equality, and not =, which is assignment.
Mar 4, 2010 at 12:24am UTC
If you don't have braces around your if statement, it only takes up one line. As a result, that else isn't attached to the if.
Last edited on Mar 4, 2010 at 12:24am UTC
Mar 4, 2010 at 12:34am UTC
please don't edit the top post just post down here and Zhuge is right
Last edited on Mar 4, 2010 at 12:34am UTC
Mar 4, 2010 at 12:36am UTC
It just disconcerts me that you have a yucky java-esque wrapper for cin... I find that most un-useful.
Mar 4, 2010 at 12:38am UTC
Teachers orders to use CinReader. He wrote the program himself. And wants all inputs to be read by it.
Mar 4, 2010 at 12:44am UTC
You are misinterpreting it completely.
It needs wrapping curly braces around the entire block of statements for each if/else if/else, not around the entire thing of ifs and elses, like so:
1 2 3 4 5 6 7 8 9 10 11 12
if (some condition)
{ // bracket HERE, before code block
// the code you want to be conditional
} // bracket here, after code block
else if (some other condition)
{
// more code
}
else
{
// more code
}
And what's the point of teaching people to use a silly nonstandard wrapper for a perfectly good class object that's standard, efficient and widely used? (If I were you, I'd tell your teacher to answer that question. But chances are you won't ask it. So this is now just rambling.)
Last edited on Mar 4, 2010 at 12:44am UTC
Mar 4, 2010 at 12:51am UTC
Thanks tummychow. Appreciate the help.
and thanks everyone else...