fork download
  1. //Adhira Balasubramani CS1A Chapter 6, pg. 369, problem #1
  2. /************************************************************************
  3.  * COMPUTE RETAIL PRICE
  4.  * ______________________________________________________________________
  5.  * This program computes the retail price of items after they get marked
  6.  * up
  7.  * ______________________________________________________________________
  8.  * INPUT
  9.  * wholesale cost : wholesale cost before markup
  10.  * markup percent : markup percentage
  11.  * OUTPUT
  12.  * retail price : calculated retail price after markup
  13.  * *********************************************************************/
  14. #include <iostream>
  15. #include <iomanip>
  16. using namespace std;
  17.  
  18. float calculateRetail (float wholesaleCost, float markupPct); //Function Prototype
  19.  
  20. int main() {
  21. float wholesaleCost;
  22. float markupPct;
  23. float retailPrice;
  24.  
  25. //Accept Inputs
  26. cout << "Enter the wholesale cost of the item\n";
  27. cin >> wholesaleCost;
  28. cout << "Enter the markup percentage\n";
  29. cin >> markupPct;
  30.  
  31. //Validate Inputs
  32. while (wholesaleCost <0)
  33. {
  34. cout << "The wholesale cost must be a positive number. Please re-enter\n";
  35. cin >> wholesaleCost;
  36. }
  37. while (markupPct <0)
  38. {
  39. cout << "The markup percentage must be a positive number. Please re-enter\n";
  40. cin >> markupPct;
  41. }
  42.  
  43. retailPrice = calculateRetail(wholesaleCost, markupPct);
  44. cout << fixed << setprecision(2) << "Retail Price of the item is $" << retailPrice;
  45. return 0;
  46. }
  47.  
  48. //Function to calculate retail price based on wholesale cost and markup percentage
  49. float calculateRetail(float wholesaleCost, float markupPct)
  50. {
  51. float result;
  52. result = wholesaleCost + (wholesaleCost * markupPct / 100);
  53. return result;
  54. }
  55.  
Success #stdin #stdout 0.01s 5296KB
stdin
-100
5.4
100
stdout
Enter the wholesale cost of the item
Enter the markup percentage
The wholesale cost must be a positive number. Please re-enter
Retail Price of the item is $105.40