running total issues
Apr 1, 2016 at 11:11pm UTC
my code is acting like a hydra... get rid of one problem, 2 more take its place. if i put in one order of each variable its fine but if i do any combo that leaves out one, it still displays that drink with some weird exponential number. no clue where to start anymore, but the total that displays the price is unaffected and the total that displays the number of drinks ordered is unaffected. help is greatly appreciated. once i can get the issue fixed i will be modify it to do this
case 'C':
case 'c':
cout << "Thank you. You have ordered the Coffee.\n" << endl;
coffee++;
break;
the code displayed is the most successful so far.
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
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
double coffee;
double juice;
double soda;
double tea;
double Manager_Special;
char choice;
int total_drinks;
double total;
do
{
cout << "Welcome to My Coffee Shop! We Offer:" << endl;
cout << "C - Coffee ($1.89)" << endl;
cout << "J - Juice ($2.99)" << endl;
cout << "S - Soda ($3.99)" << endl;
cout << "T - Tea ($4.99)" << endl;
cout << "M - Manager Special ($5.99)" << endl;
cout << "X - Done With Placing Order" << endl;
cout << "What drink would you like? Select C, J, S, T, M (or X to finish with order)" <<endl;
cin >> choice;
switch (choice)
{
case 'C' :
cout << "Thank you. You have ordered the Coffee.\n" << endl;
coffee++;
break ;
case 'c' :
cout << "Thank you. You have ordered the Coffee.\n" << endl;
coffee++;
break ;
case 'J' :
cout << "Thank you. You have ordered the Juice.\n" << endl;
juice++;
break ;
case 'j' :
cout << "Thank you. You have ordered the Juice.\n" << endl;
juice++;
break ;
case 'S' :
cout << "Thank you. You have ordered the Soda.\n" << endl;
soda++;
break ;
case 's' :
soda++;
cout << "Thank you. You have ordered the Soda.\n" << endl;
break ;
case 'T' :
cout << "Thank you. You have ordered the Tea.\n" << endl;
tea++;
break ;
case 't' :
cout << "Thank you. You have ordered the Tea.\n" << endl;
tea++;
break ;
case 'M' :
cout << "Thank you. You have order the Manager Special.\n" << endl;
Manager_Special++;
break ;
case 'm' :
cout << "Thank you. You have order the Manager Special.\n" << endl;
Manager_Special++;
break ;
case 'X' :
break ;
case 'x' :
break ;
default :
cout << "You did not enter C, J, S, T, M, or X!\n" << endl;
break ;
}
}
while (choice != 'x' && choice != 'X' );
total_drinks = coffee + juice + soda + tea + Manager_Special;
total = (coffee * 1.89) + (juice * 2.99) + (soda * 3.99) + (tea * 4.99) + (Manager_Special * 5.99);
cout << "You have ordered " << total_drinks << " drinks." << " Here is your order: " << endl;
cout << "Beverage" << setw(25) << "Quantity" << endl;
if (coffee > 0)
{
cout << "Coffee" << setw(20) << coffee << endl;
}
if (juice > 0)
{
cout << "Juice" << setw(21) << juice << endl;
}
if (soda > 0)
{
cout << "Soda" << setw(22) << soda << endl;
}
if (tea > 0)
{
cout << "Tea" << setw(23)<< tea << endl;
}
if (Manager_Special > 0)
{
cout << "Manager Special" << setw(11) << Manager_Special << endl;
}
cout << "Total: " << total << endl;
cout << "Done. Have a great day!" << endl;
return 0;
}
Last edited on Apr 1, 2016 at 11:19pm UTC
Apr 2, 2016 at 12:47am UTC
Initialize variables. Pay attention to warnings generated by the compiler.
Apr 2, 2016 at 12:57am UTC
Did ine similar yesterday maybe it can help you a lil?
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
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void display()
{
cout << "*** BASEBALL GAME SNACK MENU ***" << endl;
cout << "----------------------------------------------" << endl;
cout << "1 Hamburger $6.00" << endl;
cout << "2 Hotdog $4.50" << endl;
cout << "3 Peanuts $3.75" << endl;
cout << "4 Popcorn $5.50" << endl;
cout << "5 Soda $2.80" << endl;
cout << "6 Chips $1.00" << endl;
cout << "7 Water $2.00" << endl;
cout << "8 end order " << endl << endl;
}
void cost(double total, double tax, double tip, double totBill)
{
cout << "The subtotal is: " << setprecision(2) << fixed << total << endl;
cout << "Tip comes to: " << setprecision(2) << fixed << tip << endl;
cout << "Tax is: " << setprecision(2) << fixed << tax << endl;
cout << "Your total amount due: " << setprecision(2) << fixed << totBill << endl << endl;
}
void Tcash(double totBill, double amtTendered)
{
cout << "Please, enter amount tendered: " << endl;
cin >> amtTendered;
if (amtTendered < totBill)
{
cout << endl;
cout << "Not enough reenter: " << endl;
cin >> amtTendered;
}
cout << endl;
cout << "Change due: " << setprecision(2) << fixed << amtTendered - totBill;
cout << endl << endl;
}
int main()
{
const double hamburgerPrice = 6.00;
const double hotdogPrice = 4.50;
const double peanutsPrice = 3.75;
const double popcornPrice = 5.50;
const double sodaPrice = 2.80;
const double chipsPrice = 1.00;
const double waterPrice = 2.00;
double item;
double total = 0.0;
//displays menu
display();
while (item !=8)
{
//displays enter item until 8 is selected
cout << "Enter Menu Items #:" << endl;
cout << "----------------" << endl;
cin >> item;
cout << endl;
if (item ==1)
{
item = hamburgerPrice;
}
else if (item ==2)
{
item = hotdogPrice;
}
else if (item ==3)
{
item = peanutsPrice;
}
else if (item ==4)
{
item = popcornPrice;
}
else if ( item ==5)
{
item = sodaPrice;
}
else if (item == 6)
{
item = chipsPrice;
}
else if (item == 7)
{
item = waterPrice;
}
else if ( item == 8)
{
item = 0;
break ;
}
total += item;
}
double amtTendered;
double tip = total * .20;
double tax = total * .065;
double totBill = total + tax + tip;
cost(total, tax, tip, totBill);
Tcash( totBill, amtTendered);
}
Apr 2, 2016 at 5:40am UTC
Hi,
Can I ask you nicely not to start a new topic for the same problem :+) ?
I answered your problem yesterday, now
cire has pretty much given the exact same answer today.
If there is something you don't understand, then say so. We can explain more.
http://www.cplusplus.com/forum/general/188010/#msg913527
Apr 2, 2016 at 3:16pm UTC
i solved that issue... this is a new problem but still in the same area. and there was no warnings from the compiler. and now its fixed... now i feel like an idiot. it was initialize variables.
Apr 2, 2016 at 4:00pm UTC
and there was no warnings from the compiler.
I am sure I answered that problem in your other Topic too.
Topic archived. No new replies allowed.