fork download
  1. //Devin Scheu CS1A Chapter 6, P. 369, #1
  2. //
  3. /**************************************************************
  4. *
  5. * CALCULATE RETAIL PRICE WITH MARKUP
  6. * ____________________________________________________________
  7. * This program determines the retail price of an item based
  8. * on its wholesale cost and markup percentage.
  9. * ____________________________________________________________
  10. * INPUT
  11. * wholesaleCost : The wholesale cost of the item
  12. * markupPercentage : The markup percentage for the item
  13. *
  14. * OUTPUT
  15. * retailPrice : The calculated retail price of the item
  16. *
  17. **************************************************************/
  18.  
  19. #include <iostream>
  20. #include <iomanip>
  21.  
  22. using namespace std;
  23.  
  24. // Function to calculate retail price
  25. double calculateRetail(double wholesaleCost, double markupPercentage) {
  26. double markupAmount = wholesaleCost * (markupPercentage / 100);
  27. return wholesaleCost + markupAmount;
  28. }
  29.  
  30. int main () {
  31.  
  32. //Variable Declarations
  33. double wholesaleCost; //INPUT - The wholesale cost of the item
  34. double markupPercentage; //INPUT - The markup percentage for the item
  35. double retailPrice; //OUTPUT - The calculated retail price of the item
  36.  
  37. //Prompt for Input and Echo
  38. cout << "Enter the item's wholesale cost: $";
  39. cin >> wholesaleCost;
  40. while (wholesaleCost < 0) {
  41. cout << "\nError: Please enter a non-negative wholesale cost: $";
  42. cin >> wholesaleCost;
  43. }
  44. cout << wholesaleCost << endl;
  45.  
  46. //Prompt for Input and Echo
  47. cout << "Enter the markup percentage: ";
  48. cin >> markupPercentage;
  49. while (markupPercentage < 0) {
  50. cout << "\nError: Please enter a non-negative markup percentage: ";
  51. cin >> markupPercentage;
  52. }
  53. cout << markupPercentage << "%" << endl;
  54.  
  55. //Separator and Output Section
  56. cout << "-------------------------------------------------------" << endl;
  57. cout << "OUTPUT:" << endl;
  58.  
  59. //Calculate Retail Price
  60. retailPrice = calculateRetail(wholesaleCost, markupPercentage);
  61.  
  62. //Output Result
  63. cout << fixed << setprecision(2);
  64. cout << left << setw(25) << "Wholesale Cost:" << right << setw(15) << "$" << wholesaleCost << endl;
  65. cout << left << setw(25) << "Markup Percentage:" << right << setw(15) << markupPercentage << "%" << endl;
  66. cout << left << setw(25) << "Retail Price:" << right << setw(15) << "$" << retailPrice << endl;
  67.  
  68. } //end of main()
Success #stdin #stdout 0s 5320KB
stdin
10.00
20
stdout
Enter the item's wholesale cost: $10
Enter the markup percentage: 20%
-------------------------------------------------------
OUTPUT:
Wholesale Cost:                        $10.00
Markup Percentage:                 20.00%
Retail Price:                          $12.00