1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <iomanip>
#include <cassert>
using namespace std;
int main()
{
char answer;
float sumInEuros;
int numberOfPrices;
answer = 'Y';
numberOfPrices = 0;
sumInEuros = 0;
void processAPrice(float&, int);
void displayFinalData(float, int);
while ((answer == 'Y') || (answer == 'y'))
{
processAPrice(sumInEuros,numberOfPrices);
numberOfPrices = numberOfPrices + 1;
cout << ( " Continue (Y/N)?");
cin >> (answer);
}
if (numberOfPrices > 0)
{
displayFinalData(sumInEuros, numberOfPrices);
}
}
void processAPrice(float& sumInE, int numOfPrices)
{
float priceInPounds, priceInEuros;
const float& conversionRate = 0.82;
float getPriceInPounds(float&);
float convertPriceIntoEuros(float, float, float&);
void showPriceInEuros(float, float);
float calculateSum(float&, float);
getPriceInPounds(priceInPounds);
convertPriceIntoEuros(priceInPounds, conversionRate, priceInEuros);
showPriceInEuros(priceInPounds, priceInEuros);
calculateSum(sumInE,numOfPrices);
}
float getPriceInPounds(float& priceInP)
{
cout << ("Enter a price (in pounds): £");
cin >> (priceInP);
return(priceInP);
}
float convertPriceIntoEuros(float priceInP, float convRate, float& priceInE)
{
priceInE = priceInP / convRate;
return (priceInE);
}
void showPriceInEuros(float priceInP, float priceInE)
{
cout << ("The euro value of £", priceInP, "is €", priceInE);
}
float calculateSum(float& sumInE, float priceInE)
{
sumInE = sumInE + priceInE;
return(sumInE);
}
void displayFinalData(float sumInE, int numOfPrices)
{
cout << ("The total sum is: ", sumInE, "€");
cout << ("The average is: ", sumInE / numOfPrices);
}
|