//Zachary Abdollahi CS1A Chapter 6, P.369, #1
//
/*******************************************************************************
* CALCULATE MARKUP
* _____________________________________________________________________________
* This program asks the user for an item's wholesale cost and its markup
* percentage, then displays the item's retail price.
*
* The program uses three functions:
* getWholesale : prompts for the wholesale cost, rejects negative
* values, and returns the cost
* getMarkup : prompts for the markup percentage, rejects negative
* values, and returns the percentage
* calculateRetail : receives the wholesale cost and markup percentage
* and returns the retail price
*
* Computation is based on the formula;
* Retail Price = Wholesale Cost + (Wholesale Cost x Markup / 100)
* _____________________________________________________________________________
* INPUT
* wholesale : Item's wholesale cost
* markup : Markup percentage (100 means 100%)
*
* OUTPUT
* retail : Item's retail price
*
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
//
// Function Prototypes
double getWholesale();
double getMarkup ();
double calculateRetail(double, double);
//
int main ()
{
double wholesale; //INPUT - Item's wholesale cost
double markup; //INPUT - Markup percentage
double retail; //OUTPUT - Item's retail price
//
// Set the numeric output formatting
cout << fixed << showpoint << setprecision(2);
//
// Get Wholesale Cost and Markup Percentage
wholesale = getWholesale();
markup = getMarkup();
//
// Compute Retail Price
retail = calculateRetail(wholesale, markup);
//
// Output Result
cout << "The item's retail price is $" << retail << endl;
return 0;
}
//
//******************************************************************************
// Definition of function getWholesale. *
// This function asks the user to enter the item's wholesale cost. Negative *
// values are not accepted. *
// It returns the wholesale cost as a double. *
//******************************************************************************
double getWholesale()
{
double cost;
//
cout << "Enter the item's wholesale cost: $";
cin >> cost;
while (cost < 0)
{
cout << "Wholesale cost cannot be negative. Please re-enter: $";
cin >> cost;
}
return cost;
}
//******************************************************************************
// Definition of a function getMarkup. *
// This function asks the user to enter the markup percentage. *
// Negative values are not accepted. *
// It returns the markup percentage as a double.
//******************************************************************************
double getMarkup()
{
double percent;
//
cout << "Enter the markup percentage (example: 100 for 100%): ";
cin >> percent;
while (percent < 0)
{
cout << "Markup percentage cannot be negative. Please re-enter: ";
cin >> percent;
}
return percent;
}
//
//******************************************************************************
// Definition of a function calculateRetail. *
// This function receives an item's wholesale cost and markup percentage and *
// returns the retail price. *
//******************************************************************************
double calculateRetail(double cost, double markupPercent)
{
return cost + (cost * markupPercent / 100);
}