switch(discount)
{ case 'A': discountamt = 10;
case 'B': discountamt = 15;
case 'C': discountamt = 20;
case 'D': discountamt = 25;
}
discountpercent = (discountamt * .01);
discounttotal = (discountpercent * subtotal);
total = subtotal - discounttotal;
shipping = total * .10;
grandtotal = shipping + total;
if (milk > 0)
cout << "You entered " << milk << " pounds of Milk Chocolate @ $8.50 for a total of $" << milktotal;
if (dark > 0)
cout << "\nYou entered " << dark << " pounds of Dark Chocolate @ $9.75 for a total of $" << darktotal;
if (white > 0)
cout << "\nYou entered " << white << " pounds of White Chocolate @ $10.50 for a total of $" << whitetotal;
if (european > 0)
cout << "\nYou entered " << european << " pounds of European Chocolate @$12.50 for a total of $" << europeantotal;
if (grandtotal > 0)
cout << "\n\nYour subtotal is $" << subtotal << ".\n\nYou have received a discount of " << discountamt <<
"% for a total of $" << discounttotal << " saved" << "\nYour shipping total is $" << shipping <<
"\n\nYour grand total is $" << grandtotal;
else cout << "\nYou did not order any quantity.";
cout << "\n\nHit Any Key to Continue....";
getch();
}
#include <conio.h>
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
float milk, dark, white, european, shipping,
milktotal, darktotal, whitetotal, europeantotal,
discountpercent, discountamt, discountamount, subtotal, total, grandtotal,
discounttotal;
char discount;
cout.precision(2);
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
cout << "Enter quantity of Milk Chocolate @ $8.50 per lb ";
cin >> milk;
if (milk < 0)
milk = milk * -1;
milktotal = milk * 8.50;
cout << "\nEnter quantity of Dark European Chocolate at $9.50 per lb ";
cin >> dark;
if (dark < 0)
dark = dark * -1;
darktotal = dark * 9.75;
cout << "\nEnter quantitiy of White Chocolate @ $10.50 per lb ";
cin >> white;
if (white < 0)
white = white * -1;
whitetotal = white * 10.50;
cout << "\nEnter quantity of European Truffles @ $12.50 per lb ";
cin >> european;
if (european < 0)
european = european * -1;
europeantotal = european * 12.50;
subtotal = (milktotal + darktotal + whitetotal + europeantotal);
system("cls");
if ((subtotal >= 20.00) && (subtotal <= 39.99))
discount = 'A';
if ((subtotal >= 40.00) && (subtotal <= 59.99))
discount = 'B';
if ((subtotal >= 60.00) && (subtotal <= 79.99))
discount = 'C';
if (subtotal >= 80.00)
discount = 'D';
switch(discount)
{ case'A': discountamt = 10;
case'B': discountamt = 15;
case'C': discountamt = 20;
case'D': discountamt = 25;
}
discountpercent = (discountamt * .01);
discounttotal = (discountpercent * subtotal);
total = subtotal - discounttotal;
shipping = total * .10;
grandtotal = shipping + total;
if (milk > 0)
cout << "You entered " << milk << " pounds of Milk Chocolate @ $8.50 for a total of $" << milktotal;
if (dark > 0)
cout << "\nYou entered " << dark << " pounds of Dark Chocolate @ $9.75 for a total of $" << darktotal;
if (white > 0)
cout << "\nYou entered " << white << " pounds of White Chocolate @ $10.50 for a total of $" << whitetotal;
if (european > 0)
cout << "\nYou entered " << european << " pounds of European Chocolate @$12.50 for a total of $" << europeantotal;
if (grandtotal > 0)
cout << "\n\nYour subtotal is $" << subtotal << ".\n\nYou have received a discount of " << discountamt <<
"% for a total of $" << discounttotal << " saved" << "\nYour shipping total is $" << shipping <<
"\n\nYour grand total is $" << grandtotal;
else cout << "\nYou did not order any quantity.";
cout << "\n\nHit Any Key to Continue....";
getch();
}
A switch() statement continues until it hits "break". This means if discount is 'A', it will execute case 'A', 'B', 'C' and 'D'. If discount is 'B' it will do everything except case 'A', because case 'B' starts after case 'A'.
Add "break;" at the end of each case statement (lines 71 to 75).
Ok, I see what you mean. I did forget to put the break. thanks
Now I have another problem. When you put .2 quantity for each of them it says that I did not order any quantity. I'm wondering if this has to do with my set precision I used. I'm not too familiar with how set precision works really I just copied from the instructors examples he gave us.
#include <conio.h>
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
float milk, dark, white, european, shipping,
milktotal, darktotal, whitetotal, europeantotal,
discountpercent, discountamt, discountamount, subtotal, total, grandtotal,
discounttotal;
char discount;
cout.precision(2);
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
cout << "Enter quantity of Milk Chocolate @ $8.50 per lb ";
cin >> milk;
if (milk < 0)
milk = milk * -1.00;
milktotal = milk * 8.50;
cout << "\nEnter quantity of Dark European Chocolate at $9.50 per lb ";
cin >> dark;
if (dark < 0)
dark = dark * -1.00;
darktotal = dark * 9.75;
cout << "\nEnter quantitiy of White Chocolate @ $10.50 per lb ";
cin >> white;
if (white < 0)
white = white * -1.00;
whitetotal = white * 10.50;
cout << "\nEnter quantity of European Truffles @ $12.50 per lb ";
cin >> european;
if (european < 0)
european = european * -1.00;
europeantotal = european * 12.50;
subtotal = (milktotal + darktotal + whitetotal + europeantotal);
system("cls");
if ((subtotal >= 20.00) && (subtotal <= 39.99))
discount = 'A';
if ((subtotal >= 40.00) && (subtotal <= 59.99))
discount = 'B';
if ((subtotal >= 60.00) && (subtotal <= 79.99))
discount = 'C';
if (subtotal >= 80.00)
discount = 'D';
switch(discount)
{ case'A': discountamt = 10;
break;
case'B': discountamt = 15;
break;
case'C': discountamt = 20;
break;
case'D': discountamt = 25;
break;
}
discountpercent = (discountamt * .01);
discounttotal = (discountpercent * subtotal);
total = subtotal - discounttotal;
shipping = total * .10;
grandtotal = shipping + total;
if (milk > 0)
cout << "You entered " << milk << " pounds of Milk Chocolate @ $8.50 for a total of $" << milktotal;
if (dark > 0)
cout << "\nYou entered " << dark << " pounds of Dark Chocolate @ $9.75 for a total of $" << darktotal;
if (white > 0)
cout << "\nYou entered " << white << " pounds of White Chocolate @ $10.50 for a total of $" << whitetotal;
if (european > 0)
cout << "\nYou entered " << european << " pounds of European Chocolate @$12.50 for a total of $" << europeantotal;
if (grandtotal > 0)
cout << "\n\nYour subtotal is $" << subtotal << ".\n\nYou have received a discount of " << discountamt <<
"% for a total of $" << discounttotal << " saved" << "\nYour shipping total is $" << shipping <<
"\n\nYour grand total is $" << grandtotal;
else cout << "\nYou did not order any quantity.";
cout << "\n\nHit Any Key to Continue....";
getch();
}