reference problem

Hello, I was wondering if I could get some help with this part of my program. I will not provide the whole program as most of it is irrelevant to the part I'm having problems with.
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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <math.h>

#define MAX 30                                    

using namespace std;

struct cityInfo
{
char cityName[25];
int lowTemp;
int highTemp;
};

void calcStats(cityInfo[], int, double, double, double, double);

int main()
{
int numCities = 0;
double averagelow, averagehigh, stdlow, stdhigh;
cityInfo city[MAX];

calcStats(city, numCities, averagelow, averagehigh , stdlow, stdhigh );
cout << "\nTemperature Statistics" << endl
	 << "----------------------" << endl
	 << "Average Temperature - Low" << setw(15) << averagelow << endl
	 << "Average Temperature - High" << setw(15) << averagehigh << endl
	 << endl
	 << "Standard Deviation - Low Temperatures" << setw(15) << stdlow << endl
	 << "Standard Deviation - High Temperatures" << setw(15) << stdhigh << endl;

cout << endl;
system ("pause");

return 0;
}

void calcStats(cityInfo cities[], int numCities, double &averageLow, double &averageHigh, double &stdDevLow, double &stdDevHigh)
{
      int sumLow, sumHigh, lowSquared, highSquared;
      
       for( int i = 0; i < numCities; i++)
       {
            sumLow += cities[i].lowTemp;
            sumHigh += cities[i].highTemp;
            lowSquared += sumLow * sumLow;
            highSquared += sumHigh * sumHigh;
            averageLow = sumLow / numCities;
            averageHigh = sumHigh / numCities;
            stdDevLow = sqrt( lowSquared - ((sumLow *sumLow)/ numCities) / (numCities - 1));
            stdDevHigh = sqrt( highSquared - ((sumHigh * sumHigh)/ numCities) / (numCities - 1));
       }     
}


When I go to build and run, I get an Id returned 1 exit status error. "[Linker error] undefined reference to 'calcStats(cityInfo*, int, double, double, double, double)'.
err... you can't declare a method like you did before main.

correct me if i'm wrong. as i remember, you should be fine without the method declaration before main method. that is comment out the line. otherwise, you'd have to use declaration like this in a separate class file or header.
@xephon: That declaration is completely fine, and even required in the situation so that main() knows of the existence of the function.

@OP: Your prototype above main() needs to include & after the double variables to indicate they are references.
@Zhuge: thanks! Also thank you xephon. Thanks for the help both of you!
thanks for correcting me Zhuge. I've never done like this before. I always think this is illegal. :)
Topic archived. No new replies allowed.