fork download
  1. /*******************************************************************************
  2.  * Aiden Stannard // CS1A // Chapter 6 Homework: Challange 1# // 10/17/2026
  3.  *
  4.  * Retail Price Calculator
  5.  *
  6.  * This Program a accepts a wholesale price and retail markup percentage of an
  7.  * item and outputs the retail price.
  8.  *
  9.  * Input:
  10.  *
  11.  * Enter the item's wholesale cost in USD: $___
  12.  * Enter the markup percentage:___
  13.  *
  14.  * Output:
  15.  * This item's retail price is $___
  16.  ******************************************************************************/
  17. #include <iostream>
  18. #include <iomanip>
  19. using namespace std;
  20.  
  21. // Function prototype
  22. float calculateRetail(float wholesale, float markup);
  23.  
  24. int main()
  25. {
  26. // Holds the values of the user inputs
  27. float wholesale;
  28. float retail; // Holds the value of the return value of "calculateRetail"
  29. float markup;
  30.  
  31.  
  32. cout << "Enter the item's wholesale cost in USD: $";
  33. cin >> wholesale;
  34.  
  35. while (wholesale < 0) // stops negative inputs
  36. {
  37. cout << "The wholesale cost cannot be negative. Please re-enter: $";
  38. cin >> wholesale;
  39. }
  40.  
  41. cout << "Enter the markup percentage: ";
  42. cin >> markup;
  43.  
  44. while (markup < 0) // stops negative markup inputs
  45. {
  46. cout << "You cannot enter a negative markup. Re-enter A valid markup: ";
  47. cin >> markup;
  48. }
  49.  
  50. retail = calculateRetail(wholesale, markup);
  51.  
  52. cout << fixed << setprecision(2);
  53. cout << "This item's retail price is $" << retail << endl;
  54.  
  55. return 0;
  56. }
  57. // Calculate the retail price
  58. float calculateRetail(float wholesale, float markup)
  59. {
  60. return wholesale + (wholesale * (markup / 100.0));
  61. }
Success #stdin #stdout 0s 5320KB
stdin
6
stdout
Enter the item's wholesale cost in USD: $Enter the markup percentage: This item's retail price is $6.00