fork download
  1.  
  2. //Dione Torrevillas CS1A Chapter 6, P. 369, #1
  3. //
  4. /****************************************************************
  5.   *
  6.   * CALCULATE RETAIL PRICE
  7.   *_______________________________________________________________
  8.   * This program computes the retail price of an item based on
  9.   * its wholesale cost and markup percentage.
  10.   *
  11.   * Computation is based on the formula:
  12.   * Retail Price = Wholesale Cost +
  13.   * (Wholesale Cost * Markup Percentage / 100)
  14.   *_______________________________________________________________
  15.   * INPUT
  16.   * wholesaleCost : Wholesale cost of the item
  17.   * markupPercent : Markup percentage of the item
  18.   *
  19.   * OUTPUT
  20.   * retailPrice : Retail price of the item
  21.   *
  22.   ****************************************************************/
  23.  
  24. #include <iostream>
  25. #include <iomanip>
  26. using namespace std;
  27.  
  28. // Function prototype
  29. double calculateRetail(double, double);
  30.  
  31. int main()
  32. {
  33. double wholesaleCost; //INPUT - Wholesale cost of item
  34. double markupPercent; //INPUT - Markup percentage
  35. double retailPrice; //OUTPUT - Retail price of item
  36.  
  37. // Get wholesale cost
  38. cout << "Enter the wholesale cost: $";
  39. cin >> wholesaleCost;
  40.  
  41. // Validate wholesale cost
  42. while (wholesaleCost < 0)
  43. {
  44. cout << "Enter a nonnegative cost: $";
  45. cin >> wholesaleCost;
  46. }
  47.  
  48. // Get markup percentage
  49. cout << "Enter the markup percentage: ";
  50. cin >> markupPercent;
  51.  
  52. // Validate markup percentage
  53. while (markupPercent < 0)
  54. {
  55. cout << "Enter a nonnegative percentage: ";
  56. cin >> markupPercent;
  57. }
  58.  
  59. // Calculate the retail price
  60. retailPrice = calculateRetail(wholesaleCost,
  61. markupPercent);
  62.  
  63. // Display the retail price
  64. cout << fixed << setprecision(2);
  65. cout << "The retail price is: $"
  66. << retailPrice << endl;
  67.  
  68. return 0;
  69. }
  70.  
  71. // Function definition
  72. double calculateRetail(double cost, double percent)
  73. {
  74. double retailPrice;
  75.  
  76. retailPrice = cost + (cost * percent / 100);
  77.  
  78. return retailPrice;
  79. }
  80.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Enter the wholesale cost: $Enter the markup percentage: The retail price is: $0.00