Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. float numberOfPrices;
  7. float sumInEuros;
  8. char answer;
  9.  
  10. float processAPrice(float);
  11. void displayFinalData(float&, float);
  12.  
  13. numberOfPrices = 0;
  14. sumInEuros = 0;
  15. answer = 'Y';
  16.  
  17. while ((answer = 'Y') || (answer = 'y')) {
  18. processAPrice(sumInEuros);
  19. numberOfPrices = numberOfPrices + 1;
  20. cout << ("Continue (Y/N)?\n");
  21. cin >> answer;
  22. }
  23. if (numberOfPrices > 0)
  24. displayFinalData(sumInEuros, numberOfPrices);
  25. return(0);
  26. }
  27.  
  28. float processAPrice()
  29. {
  30. float priceInPounds;
  31. float priceInEuros;
  32.  
  33. float getPriceInPounds(float);
  34. float convertPriceInEuros(float);
  35. float showPriceInEuros(float, float);
  36. float calculateSum(float&, float);
  37.  
  38. priceInPounds = getPriceInPounds(priceInPounds);
  39. convertPriceInEuros(priceInPounds);
  40. sumInEuros = showPriceInEuros(priceInPounds, priceInEuros);
  41. calculateSum(sumInEuros, numberOfPrices);
  42.  
  43. return;
  44. }
  45.  
  46.  
  47. float getPriceInPounds(float priceInPounds)
  48. {
  49. cout << ("Enter a price (in pounds): £ \n");
  50. cin >> priceInPounds;
  51. return priceInPounds;
  52. }
  53.  
  54.  
  55. float convertPriceIntoEuros(float priceInPounds, float priceInEuros)
  56. {
  57. const float conversionRate = 0.82f;
  58. priceInEuros = priceInPounds / conversionRate;
  59. return priceInEuros;
  60. }
  61.  
  62.  
  63. void showPriceInEuros(float priceInPounds, float priceInEuros)
  64. {
  65. cout << ("The euro value of £") << priceInPounds << ("is €") << priceInEuros;
  66. }
  67.  
  68.  
  69. float calculateSum(float& sumInEuros, float priceInEuros)
  70. {
  71. sumInEuros = sumInEuros + priceInEuros;
  72. return sumInEuros;
  73. }
  74.  
  75. void displayFinalData(float& sumInEuros, float numberOfPrices)
  76. {
  77. cout << ("The total sum is: ") << sumInEuros << ("€");
  78. cout << ("The average is: ") << (sumInEuros / numberOfPrices);
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement