Parameters

Hi guys, I'm fairly new with c++ and I have been trying to make a pound to euro conversion program with only local variables and parameters, I think I'm fairly close, I can get the conversion from pounds to euros to work but I can't seem to get any of the couts or the total sum to work. Have I done something severely wrong with the parameter passing?

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);
}
Last edited on
For cout do not use commas, instead <<

1
2
	cout << "The total sum is: " << sumInE << "€";
	cout << "The average is: " << sumInE / numOfPrices);
Ahh, can't believe I didn't spot that, thanks coder! :)

I also feel like I did something wrong with the parameters, is that the case?
Last edited on
I also feel like I did something wrong with the parameters, is that the case?
No, it's kind of odd that you place the prototypes within a function and pass a reference for the return value, but it's not wrong.
I got it to work!
also, good point, I'll remember that in future, cheers coder! :)
Topic archived. No new replies allowed.