Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- float numberOfPrices;
- float sumInEuros;
- char answer;
- float processAPrice(float);
- void displayFinalData(float&, float);
- numberOfPrices = 0;
- sumInEuros = 0;
- answer = 'Y';
- while ((answer = 'Y') || (answer = 'y')) {
- processAPrice(sumInEuros);
- numberOfPrices = numberOfPrices + 1;
- cout << ("Continue (Y/N)?\n");
- cin >> answer;
- }
- if (numberOfPrices > 0)
- displayFinalData(sumInEuros, numberOfPrices);
- return(0);
- }
- float processAPrice()
- {
- float priceInPounds;
- float priceInEuros;
- float getPriceInPounds(float);
- float convertPriceInEuros(float);
- float showPriceInEuros(float, float);
- float calculateSum(float&, float);
- priceInPounds = getPriceInPounds(priceInPounds);
- convertPriceInEuros(priceInPounds);
- sumInEuros = showPriceInEuros(priceInPounds, priceInEuros);
- calculateSum(sumInEuros, numberOfPrices);
- return;
- }
- float getPriceInPounds(float priceInPounds)
- {
- cout << ("Enter a price (in pounds): £ \n");
- cin >> priceInPounds;
- return priceInPounds;
- }
- float convertPriceIntoEuros(float priceInPounds, float priceInEuros)
- {
- const float conversionRate = 0.82f;
- priceInEuros = priceInPounds / conversionRate;
- return priceInEuros;
- }
- void showPriceInEuros(float priceInPounds, float priceInEuros)
- {
- cout << ("The euro value of £") << priceInPounds << ("is €") << priceInEuros;
- }
- float calculateSum(float& sumInEuros, float priceInEuros)
- {
- sumInEuros = sumInEuros + priceInEuros;
- return sumInEuros;
- }
- void displayFinalData(float& sumInEuros, float numberOfPrices)
- {
- cout << ("The total sum is: ") << sumInEuros << ("€");
- cout << ("The average is: ") << (sumInEuros / numberOfPrices);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement