Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- /*
- Programmer: Bryan Virgil
- Date: 10 04 2017
- Description: Tshirt company is giving the following discounts
- 1..5 --> 0% discounts
- 6..10 --> 10% discounts
- 10+ --> 25% discounts*/
- using namespace std;
- const int TSHIRT_PRICE = 10;
- const double DISCOUNT_5_PCT = 0.05;
- const double DISCOUNT_10_PCT = 0.10;
- const double DISCOUNT_15_PCT = 0.15;
- const double DISCOUNT_20_PCT = 0.20;
- const double DISCOUNT_25_PCT = 0.25;
- int main()
- {
- int numTShirts; // used to hold number of thisrts purchased
- double discount = 0;
- cout << "How many T-Shirts did you purchase:";
- cin >> numTShirts;
- if (cin.fail())
- {
- cout << "Wrong data type, please run the program" << endl;
- }
- else
- {
- if (numTShirts < 1)
- {
- cout << "Invalid quantity, please run the program again" << endl;
- cout << "Exiting..." << endl;
- // exit(EXIT_FAILURE);
- // use else statement to get rid of EXIT_FAILURE
- }
- // get rid of the exit and implement the else part
- // else
- else
- switch(numTShirts)
- {
- case 1 ... 5:
- totalPrie - numTShirts * TSHIRT_PRICE + discount;
- cout << "You get 0% discount" << endl;
- break;
- case 6 ... 10:
- cout << "You get 5% discount" << endl;
- subtotal = numTShirts * TSHIRT_PRICE;
- discount = subTotal * DISCOUNT_5_PCT;
- totalPrice = subTotal - discount;
- break;
- case 11 ... 20:
- cout << "You get 10% discount" << endl;
- subtotal = numTShirts * TSHIRT_PRICE;
- discount = subTotal * DISCOUNT_10_PCT;
- totalPrice = subTotal - discount;
- break;
- case 21 ... 50:
- cout << "You get 15% discount" << endl;
- subtotal = numTShirts * TSHIRT_PRICE;
- discount = subTotal * DISCOUNT_15_PCT;
- totalPrice = subTotal - discount;
- break;
- case 51 ... 100:
- cout << "You get 20% discount" << endl;
- subtotal = numTShirts * TSHIRT_PRICE;
- discount = subTotal * DISCOUNT_20_PCT;
- totalPrice = subTotal - discount;
- break;
- default:
- cout << "Call for discount" << endl;
- }
- cout << "You purchased: " << numTShirts << endl;
- cout << "Your subtotal was $: " << subTotal << endl;
- cout << "Your discount was $: " << discount << endl;
- cout << "Your total price was $ " << totalPrice << endl;
- cout << "" <<
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement