fork download
  1. //Eric Bernal CS1A Chapter 6, P. 369, #1
  2. //
  3. /*******************************************************************************
  4.  * CALCULATE WHOLESALE RETAIL MARKUP PRICE
  5.  * _____________________________________________________________________________
  6.  * This program is given a mark up percentage and a wholesale price, which then
  7.  * calculates the values to produce the retail cost.
  8.  * _____________________________________________________________________________
  9.  * Input
  10.  * markupPercent : A given mark up that is a percentage.
  11.  * wholesale : A given wholesale price.
  12.  *
  13.  * Output
  14.  * retailPrice : The cost of the retail item after the markup price.
  15.  ******************************************************************************/
  16. #include <iostream>
  17. #include <iomanip>
  18. using namespace std;
  19.  
  20. // Function Prototype
  21. float calculateRetail(float markUp, float Cost);
  22.  
  23. int main() {
  24. // Data Dictionary - Initialize all Variables
  25. float markupPercent; //INPUT : A given markup as a percentage.
  26. float wholesale; //INPUT : A given wholesale cost.
  27. float retailCost; //OUTPUT: The retail price after markup.
  28.  
  29. //Obtain Mark Up Percentage and Wholesale Price
  30. cout << "Enter the mark up percentage as a whole number." << endl;
  31. cin >> markupPercent;
  32. cout << "Enter the wholesale price of the item." << endl;
  33. cin >> wholesale;
  34.  
  35. // Input Validation
  36. if (markupPercent >= 100 || markupPercent <= 0)
  37. {
  38. cout << "Error: Please enter a positive value from 0 to 100." << endl;
  39. cin >> markupPercent;
  40. }
  41. if (wholesale <= 0)
  42. {
  43. cout << "Error: Please enter a positive whole number." << endl;
  44. cin >> wholesale;
  45. }
  46.  
  47. //Calculate retail price + Function Call
  48. retailCost = calculateRetail(markupPercent, wholesale);
  49.  
  50. // Output display
  51. cout << "Wholesale Price : " << wholesale << "\nMarkup Percentage Rate: "
  52. << markupPercent << "\nRetail Price : " << retailCost << endl;
  53.  
  54. return 0;
  55. }
  56.  
  57. /*******************************************************************************
  58.  * This function's purpose is to calculate the retail price of an item.
  59.  ******************************************************************************/
  60. //Function Header
  61. float calculateRetail(float a, float b)
  62. {
  63. float c;
  64. c = b + (b*(a/100));
  65. return c;
  66. }
Success #stdin #stdout 0.01s 5296KB
stdin
100
5
stdout
Enter the mark up percentage as a whole number.
Enter the wholesale price of the item.
Error: Please enter a positive value from 0 to 100.
Wholesale Price : 5
Markup Percentage Rate: 100
Retail Price : 10