fork download
  1. //Timothy Price CS1A Ch 6 challenge 1
  2. /*******************************************************************************
  3.  * Calculate markup
  4.  *
  5.  * This program receives a cost and percentage and calculates the markup price
  6.  *
  7.  * Input:
  8.  * wholesale cost
  9.  * markup percentage
  10.  *
  11.  * Output:
  12.  * retail cost
  13. *******************************************************************************/
  14.  
  15. #include <iostream>
  16. #include <iomanip>
  17. using namespace std;
  18.  
  19. //function prototype
  20. // float calculateRetail(float, float);
  21. float calculateRetail(float w, float x) {
  22. x /= 100;
  23. float y = w * x;
  24. float z = y + w;
  25. return z;
  26. }
  27.  
  28. int main() {
  29.  
  30. //data dictionary
  31. float wholesale_cost;
  32. float markup_rate;
  33. float retail_cost;
  34.  
  35. cout << "Enter the item's wholesale cost: ";
  36. cin >> wholesale_cost;
  37. cout << "$" << wholesale_cost << endl;
  38. cout << "Enter the item's markup percentage: ";
  39. cin >> markup_rate;
  40. cout << markup_rate << "%" << endl;
  41.  
  42. //input validation
  43. if (wholesale_cost <= 0.00) {
  44. cout << "Wholesale cost can't be less than or equal to $0.00,";
  45. cout << " try again";
  46. }
  47. else if (markup_rate <= 0.00) {
  48. cout << "Percentage can't be less than or equal to 0.00, try again";
  49. }
  50. else if (wholesale_cost > 0.00 && markup_rate > 0.00) {
  51. //call function to calculate retail cost
  52. calculateRetail(wholesale_cost, markup_rate);
  53. float retail_cost = calculateRetail(wholesale_cost, markup_rate);
  54.  
  55. //display retail cost
  56. cout << fixed << setprecision(2);
  57. cout << "The retail cost of this item is $" << retail_cost;
  58. }
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0.01s 5292KB
stdin
120
15



stdout
Enter the item's wholesale cost: $120
Enter the item's markup percentage: 15%
The retail cost of this item is $138.00