here is the assignment, but cant seem to figure out how to implement the discounts and the shipping and handling
The store sells chocolates:
• Milk Chocolate @ $8.50 per pound
• Dark European Chocolate @ $9.75 per pound
• White Chocolate @ $10.50 per pound
• European Truffles @ $12.50 per pound
The store allows a customer discount based on:
1. $20.00 to $39.99 10% off
2. $40.00 to $59.99 15% off
3. $60.00 to $79.99 20% off
4. $80.00 and over 25% off
Shipping & Handling is 10% of the net total (gross – discount).
Total Owed is Net Total plus Shipping and Handling)
You are using the switch to calculate the quantity discount. Since the switch does not allow a range, you have to set a “code” for the quantity range to use in the Switch such as and integer code 1, 2, 3, or 4 or maybe a char ‘a’, ‘b’, ‘c’ or ‘d’.
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
int choice; // Hold a menu of choice
int pounds; // Hold the number of pounds
double charges; // Hold the price range
float discout; //Hold discount range
// Constants for amount in pounds
const double
milkChocolate = 8.50,
darkEuropeanChocolate = 9.75,
whiteChocolate = 10.50,
europeanTruffles = 12.50;
// Constans for menu choices
const int
milkChocolate_Choice = 1,
darkEuropeanChocolate_Choice = 2,
whiteChocolate_Choice = 3,
europeanTruffles_Choice = 4,
terminate_Choice = 5;
// Display menu and chose a choice
cout << "\t\tChocolate Menu \n\n"
<< "1. milkChocolate\n"
<< "2. darkeuropeanChocolate\n"
<< "3. whiteChocolate\n"
<< "4. europeanTruffles\n"
<< "5. terminate program\n\n"
<< "Enter your choice of chocolate: ";
cin >> choice;
// Respond to users menu selection
switch (choice)
{
case milkChocolate_Choice:
cout << "How many pounds? ";
cin >> pounds;
charges = (pounds * milkChocolate) / discount;
cout << "The total Price including dicount is $" << charges << endl;
break;
case darkEuropeanChocolate_Choice:
cout << "How many pounds? ";
cin >> pounds;
charges = pounds * darkEuropeanChocolate;
cout << "The total after the discount is $" << charges << endl;
break;
case whiteChocolate_Choice:
cout << "How many pounds? ";
cin >> pounds;
charges = pounds * whiteChocolate;
cout << "The total after the discount is $" << charges << endl;
break;
case europeanTruffles_Choice:
cout << "How many pounds? ";
cin >> pounds;
charges = pounds * europeanTruffles;
cout << "The total after the discount is $" << charges << endl;
break;
This is very, very wrong. First of all, it isn't valid syntactically: const float identifier = value. Second, 20 will never ever be greater than 40, 40 will never ever be less than or equal to 20 and so on. Third (though not a serious issue in this case), favor double over float.
What you need to do is find out what the charges are (which you do) then, from that, calculate the discount. Example:
1 2 3 4 5
double discount = 0;
if (charges >= 20.00 && charges < 40.00) discount = 0.1;
elseif(/*and check for the rest of the ranges; you can do that*/)
//then apply the discount,
//calculate and apply the shipping and handling
still trying to figure out where the if statement should be placed this is what i did but think i still missing the declaration of the discount into the formula:
switch (choice)
{
if (charges >=20.00 && charges < 40.00) discount = 0.1;
case milkChocolate_Choice:
cout << "How many pounds? ";
cin >> pounds;
charges = pounds * milkChocolate * discount;
cout << "The total after the the discount is $" << charges << discount << endl;
break;
if (charges >=40.00 && charges < 60.00) discount = .15;
case darkEuropeanChocolate_Choice:
cout << "How many pounds? ";
cin >> pounds;
charges = pounds * darkEuropeanChocolate * discount;
cout << "The total after the discount is $" << charges << endl;
break;
if (charges >= 60.00 && charges < 80.00) discount = 0.2;
case whiteChocolate_Choice:
cout << "How many pounds? ";
cin >> pounds;
charges = pounds * whiteChocolate * discount;
cout << "The total after the discount is $" << charges << endl;
break;
if (charges >= 80.00) discount = 0.25;
case europeanTruffles_Choice:
cout << "How many pounds? ";
cin >> pounds;
charges = pounds * europeanTruffles * discount;
cout << "The total after the discount is $" << charges << endl;
break;