fork download
  1. //Amari Mosley CSC5 Chapter 6, P. 369, #1
  2. //
  3. /*****************************************************************
  4.  *
  5.  * Calculate Markup
  6.  * _______________________________________________________________
  7.  * This program computes the retail price of an item based on its
  8.  * wholesale cost and markup percentage.
  9.  *
  10.  * Computation is based on the formula:
  11.  * retail = wholesale + (wholesale * (markup / 100))
  12.  * _______________________________________________________________
  13.  * INPUT
  14.  * wholesale : the item's wholesale cost (must not be negative)
  15.  * markup : the markup percentage (must not be negative)
  16.  *
  17.  * OUTPUT
  18.  * retail : the item's retail price
  19.  *
  20.  *****************************************************************/
  21. #include <iostream>
  22. #include <iomanip>
  23. using namespace std;
  24.  
  25. // Function prototype
  26. double calculateRetail(double wholesale, double markup);
  27.  
  28. int main()
  29. {
  30. double wholesale; // wholesale cost of the item
  31. double markup; // markup percentage
  32. double retail; // retail price of the item
  33.  
  34. // Get wholesale cost with input validation
  35. cout << "Enter the item's wholesale cost: $";
  36. cin >> wholesale;
  37. while (wholesale < 0)
  38. {
  39. cout << "Wholesale cost cannot be negative. Please re-enter: $";
  40. cin >> wholesale;
  41. }
  42.  
  43. // Get markup percentage with input validation
  44. cout << "Enter the markup percentage: ";
  45. cin >> markup;
  46. while (markup < 0)
  47. {
  48. cout << "Markup percentage cannot be negative. Please re-enter: ";
  49. cin >> markup;
  50. }
  51.  
  52. // Calculate and display the retail price
  53. retail = calculateRetail(wholesale, markup);
  54.  
  55. cout << fixed << setprecision(2);
  56. cout << "The item's retail price is $" << retail << endl;
  57.  
  58. return 0;
  59. }
  60.  
  61.  
  62. // calculateRetail
  63. // Receives the wholesale cost and markup percentage and
  64. // returns the retail price of the item.
  65.  
  66. double calculateRetail(double wholesale, double markup)
  67. {
  68. return wholesale + (wholesale * (markup / 100));
  69. }
Success #stdin #stdout 0s 5320KB
stdin
5.00
100
stdout
Enter the item's wholesale cost: $Enter the markup percentage: The item's retail price is $10.00