fork download
  1. //Zachary Abdollahi CS1A Chapter 6, P.369, #1
  2. //
  3. /*******************************************************************************
  4.  * CALCULATE MARKUP
  5.  * _____________________________________________________________________________
  6.  * This program asks the user for an item's wholesale cost and its markup
  7.  * percentage, then displays the item's retail price.
  8.  *
  9.  * The program uses three functions:
  10.  * getWholesale : prompts for the wholesale cost, rejects negative
  11.  * values, and returns the cost
  12.  * getMarkup : prompts for the markup percentage, rejects negative
  13.  * values, and returns the percentage
  14.  * calculateRetail : receives the wholesale cost and markup percentage
  15.  * and returns the retail price
  16.  *
  17.  * Computation is based on the formula;
  18.  * Retail Price = Wholesale Cost + (Wholesale Cost x Markup / 100)
  19.  * _____________________________________________________________________________
  20.  * INPUT
  21.  * wholesale : Item's wholesale cost
  22.  * markup : Markup percentage (100 means 100%)
  23.  *
  24.  * OUTPUT
  25.  * retail : Item's retail price
  26.  *
  27.  ******************************************************************************/
  28. #include <iostream>
  29. #include <iomanip>
  30. using namespace std;
  31. //
  32. // Function Prototypes
  33. double getWholesale();
  34. double getMarkup ();
  35. double calculateRetail(double, double);
  36. //
  37. int main ()
  38. {
  39. double wholesale; //INPUT - Item's wholesale cost
  40. double markup; //INPUT - Markup percentage
  41. double retail; //OUTPUT - Item's retail price
  42. //
  43. // Set the numeric output formatting
  44. cout << fixed << showpoint << setprecision(2);
  45. //
  46. // Get Wholesale Cost and Markup Percentage
  47. wholesale = getWholesale();
  48. markup = getMarkup();
  49. //
  50. // Compute Retail Price
  51. retail = calculateRetail(wholesale, markup);
  52. //
  53. // Output Result
  54. cout << "The item's retail price is $" << retail << endl;
  55. return 0;
  56. }
  57. //
  58. //******************************************************************************
  59. // Definition of function getWholesale. *
  60. // This function asks the user to enter the item's wholesale cost. Negative *
  61. // values are not accepted. *
  62. // It returns the wholesale cost as a double. *
  63. //******************************************************************************
  64. double getWholesale()
  65. {
  66. double cost;
  67. //
  68. cout << "Enter the item's wholesale cost: $";
  69. cin >> cost;
  70. while (cost < 0)
  71. {
  72. cout << "Wholesale cost cannot be negative. Please re-enter: $";
  73. cin >> cost;
  74. }
  75. return cost;
  76. }
  77. //******************************************************************************
  78. // Definition of a function getMarkup. *
  79. // This function asks the user to enter the markup percentage. *
  80. // Negative values are not accepted. *
  81. // It returns the markup percentage as a double.
  82. //******************************************************************************
  83. double getMarkup()
  84. {
  85. double percent;
  86. //
  87. cout << "Enter the markup percentage (example: 100 for 100%): ";
  88. cin >> percent;
  89. while (percent < 0)
  90. {
  91. cout << "Markup percentage cannot be negative. Please re-enter: ";
  92. cin >> percent;
  93. }
  94. return percent;
  95. }
  96. //
  97. //******************************************************************************
  98. // Definition of a function calculateRetail. *
  99. // This function receives an item's wholesale cost and markup percentage and *
  100. // returns the retail price. *
  101. //******************************************************************************
  102. double calculateRetail(double cost, double markupPercent)
  103. {
  104. return cost + (cost * markupPercent / 100);
  105. }
Success #stdin #stdout 0.01s 5316KB
stdin
5
100
5
50
stdout
Enter the item's wholesale cost: $Enter the markup percentage (example: 100 for 100%): The item's retail price is $10.00