### 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.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556`` ``````#include #include #include #include #include #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.