fork download
  1. //Andres Guzman CSC5 Chapter 6, P. 369, #1
  2. //
  3. /*******************************************************************************
  4. *
  5. * CALCULATE RETAIL PRICE
  6. * ______________________________________________________________________________
  7. * This program will calculate the retail price of a wholesale item after markup
  8. *
  9. * Computation:
  10. *
  11. * retail = wholesale + (wholesale * markup / 100)
  12. * ______________________________________________________________________________
  13. * INPUT
  14. *
  15. * float wholesale = Original cost of an item
  16. * float markup = percentage increase
  17. *OUTPUT
  18. * float retail = price of item after increase
  19. *
  20. *******************************************************************************/
  21. #include <iostream>
  22. #include <iomanip>
  23. using namespace std;
  24.  
  25. float wholesale; //Global Variable
  26. float markup; //Global Variable
  27. float retail; //Global Variable
  28.  
  29. void calculateretail(float wholesale, float markup); //prototype
  30. int main ()
  31. {
  32. //
  33. //Ask user for wholesale
  34. cout << "Wholesale Cost: $";
  35. cin >> wholesale;
  36. //
  37. //Creating while loop for input validation
  38. while(wholesale < 0)
  39. {
  40. cout << "\nInvalid Input, please enter positive values. ";
  41. cout << "\n\nWholesale Cost: $";
  42. cin >> wholesale;
  43. }
  44. //
  45. //Ask user for markup
  46. cout << "\nMarkup Percentage: %";
  47. cin >> markup;
  48. //
  49. //Creating while loop for input validation
  50. while(markup < 0)
  51. {
  52. cout << "\nInvalid Input, please enter positive values. ";
  53. cout << "\n\nWholesale Cost: $";
  54. cin >> markup;
  55. }
  56. calculateretail(wholesale, markup); //function call
  57.  
  58. cout << fixed << setprecision(2) << "\nRetail Price: $" << retail << endl;
  59.  
  60. return 0;
  61. }
  62.  
  63. /*******************************************************************************
  64.  * Adding definition to function calculateretail. Parameters hold wholesale and
  65.  * markup variables. Function will calculate the retail price.
  66.  ******************************************************************************/
  67. void calculateretail(float wholesale, float markup)
  68. {
  69. retail = wholesale + (wholesale * markup / 100);
  70. }
Success #stdin #stdout 0s 5320KB
stdin
5 100
stdout
Wholesale Cost: $
Markup Percentage: %
Retail Price: $10.00