I'm writing a program that calculates the average of three temperatures using functions, and for some reason my output is always 0.0 in it. I'm not sure if it has something to do with the placement of the variables inside the code, or if I'm supposed to initialize at least one of them, but the fact is I can't seem to find out what the problem is. I'm still pretty new to programming, and to programming that involves functions and objects. Is there something that I'm missing here?
void getTemps(double);
double calcAvg(double tempAvg);
void displayAvg();
double temp1, temp2, temp3;
double sum;
float tempAvg;
int main()
{
getTemps(sum);
calcAvg(tempAvg);
displayAvg();
system("PAUSE");
return 0;
}
void getTemps(double sum)
{
// Get up to three temperatures
cout << "Enter temperatures of 3 cities." << endl;
cin >> temp1;
cin >> temp2;
cin >> temp3;
sum = temp1 + temp2 + temp3;
}
double calcAvg(double tempAvg)
{
tempAvg = (sum / 3);
return tempAvg;
}
void displayAvg()
{
cout << fixed << setprecision(1) << temp1 << endl;
cout << fixed << setprecision(1) << temp2 << endl;
cout << fixed << setprecision(1) << temp3 << endl;
cout << "The average temperature is " << tempAvg << " degrees." << endl;
}