Void Returning Function - Assigning Inputs to Variables

Okay, so I was asked to use functions in order to write a program that prompts the user to enter three different temperatures and then output the average of the temperatures.

It runs fine but I get garbage as the output. I am mostly having trouble with not being sure how to assign user input to the variables in the void function getTemp. This is also where i suspect the problem to be at. Any help is appreciated. Thanks in advance.

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
#include<iostream>
#include<iomanip>
using namespace std;

void getTemps();
double calcAvg(double & temp1, double & temp2, double & temp3);
void displayAvg(double avgTemp);

int main()
{
	double avgTemp;
	double temp1, temp2, temp3;

	getTemps();
	avgTemp = calcAvg(temp1, temp2, temp3);
	displayAvg(avgTemp);

	return 0;

}
void getTemps()
{
	double temp1, temp2, temp3;

	cout << "Enter temperatures of 3 cities. \n";
	
	cout << "#1: ";
	cin >> temp1;
	cout << endl;

	cout << "#2: ";
	cin >> temp2;
	cout << endl;

	cout << "#3: ";
	cin >> temp3;
	cout << endl;
}
double calcAvg(double & temp1, double & temp2, double & temp3)
{
	double avgTemp;

	avgTemp = (temp1 + temp2 + temp3)/3;
	
	return avgTemp;
}
void displayAvg(double avgTemp)
{
	cout << "The average temperature is " << 
	setprecision(2) << fixed << showpoint << avgTemp << " degrees.";
}
The variables declared on line 12 and the ones declared on line 23 are unconnected. Lines 28, 32, and 36 modify the values of the ones from 23, not of the ones from 12.

thank you helios for the clarification!
Topic archived. No new replies allowed.