//Dione Torrevillas CS1A Chapter 6, P. 369, #1
//
/****************************************************************
*
* CALCULATE RETAIL PRICE
*_______________________________________________________________
* This program computes the retail price of an item based on
* its wholesale cost and markup percentage.
*
* Computation is based on the formula:
* Retail Price = Wholesale Cost +
* (Wholesale Cost * Markup Percentage / 100)
*_______________________________________________________________
* INPUT
* wholesaleCost : Wholesale cost of the item
* markupPercent : Markup percentage of the item
*
* OUTPUT
* retailPrice : Retail price of the item
*
****************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototype
double calculateRetail(double, double);
int main()
{
double wholesaleCost; //INPUT - Wholesale cost of item
double markupPercent; //INPUT - Markup percentage
double retailPrice; //OUTPUT - Retail price of item
// Get wholesale cost
cout << "Enter the wholesale cost: $";
cin >> wholesaleCost;
// Validate wholesale cost
while (wholesaleCost < 0)
{
cout << "Enter a nonnegative cost: $";
cin >> wholesaleCost;
}
// Get markup percentage
cout << "Enter the markup percentage: ";
cin >> markupPercent;
// Validate markup percentage
while (markupPercent < 0)
{
cout << "Enter a nonnegative percentage: ";
cin >> markupPercent;
}
// Calculate the retail price
retailPrice = calculateRetail(wholesaleCost,
markupPercent);
// Display the retail price
cout << fixed << setprecision(2);
cout << "The retail price is: $"
<< retailPrice << endl;
return 0;
}
// Function definition
double calculateRetail(double cost, double percent)
{
double retailPrice;
retailPrice = cost + (cost * percent / 100);
return retailPrice;
}