/* Software Sales - A software company sells a package that retails at $99. Quantity
discounts are given according to the following table:
Quantity Discount
10-19 20%
20-49 30%
50-99 40%
100 or more 50%
This program asks for the number of units sold and computes the total cost of the
purchase.
* Input Validation: The number of units has to be greater than 0. */
#include "Utility.h"
int main()
{
/* Hold constant for retail price */
const float RETAIL_PRICE = 99.0;
/* Hold sales, quantity and discount */
float quantity,
discount,
sumTotal;
/* Ask the user for the quantity sold */
cout << "Enter the amount of units sold: ";
cin >> quantity;
/* Format the output */
cout << fixed << showpoint << setprecision(2);
if (quantity > 0 && quantity < 10)
{
sumTotal = (quantity * RETAIL_PRICE);
cout << "Sum Total: $" << sumTotal << endl;
}
else if (quantity >= 10 && quantity <= 19)
{
discount = (quantity * RETAIL_PRICE) * .2;
sumTotal = (quantity * RETAIL_PRICE) - discount;
cout << "Sum Total: $" << sumTotal << endl;
}
else if (quantity >= 20 && quantity <= 49)
{
discount = (quantity * RETAIL_PRICE) * .3;
sumTotal = (quantity * RETAIL_PRICE) - discount;
}
else if (quantity >= 50 && quantity <= 99)
{
discount = (quantity * RETAIL_PRICE) * .4;
sumTotal = (quantity * RETAIL_PRICE) - discount;
cout << "Sum Total: $" << sumTotal << endl;
}
else if (quantity >= 100)
{
discount = (quantity * RETAIL_PRICE) * .5;
sumTotal = (quantity * RETAIL_PRICE) - discount;
cout << "Sum Total: $" << sumTotal << endl;
}
else
{
cout << "The quantity must be greater than 0.\n";
}
pauseSystem();
return 0;
}
Tuesday, November 22, 2016
Programming Challenge 4.12 - Software Sales
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment