fork download
  1. //Matthew Santos CS1A Ch. 6, Pg. 239, #1
  2. /***********************************************
  3.  *
  4.  * CALCULATE RETAIL PRICE
  5.  * _____________________________________________
  6.  * Calculates the retail price of an item based
  7.  * off the wholesale cost and markup percentage.
  8.  * _____________________________________________
  9.  * INPUT
  10.  * wholesaleCost : wholesale cost of item
  11.  * markupPercent : markup percentage of item
  12.  *
  13.  * OUTPUT
  14.  * retail : retail price of item
  15.  ***********************************************/
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. double calculateRetail(double, double);
  20.  
  21. int main() {
  22. double wholesaleCost;
  23. double markupPercent;
  24. double retialPrice;
  25.  
  26. // Ask for input
  27. cout << "Enter the item's wholesale cost: ";
  28. cin >> wholesaleCost;
  29.  
  30. // Validate inputs
  31. while (wholesaleCost < 0) {
  32. cout << "Wholesale cost cannot be negative. Enter again: ";
  33. cin >> wholesaleCost;
  34. }
  35.  
  36. cout << "Enter the item's markup percentage: ";
  37. cin >> markupPercent;
  38.  
  39. while (markupPercent < 0) {
  40. cout << "Markup percentage cannot be negative. Enter again: ";
  41. cin >> markupPercent;
  42. }
  43.  
  44. // Calculate and display retail price
  45. double retailPrice = calculateRetail(wholesaleCost, markupPercent);
  46. cout << "The item's retail price is $" << retailPrice << endl;
  47.  
  48. return 0;
  49. }
  50.  
  51. double calculateRetail(double wholesaleCost, double markupPercent)
  52. {
  53. return wholesaleCost + (wholesaleCost * markupPercent / 100);
  54. }
Success #stdin #stdout 0s 5324KB
stdin
30 5
stdout
Enter the item's wholesale cost: Enter the item's markup percentage: The item's retail price is $31.5