C
Comcast
Can anyone help:
When I compile this code, I'm getting
[{Linker error] undefined reference to 'getData(WeatherStats*,int)'
I'm not sure what is causing the error.
Thanks
Art
// This program creates a weather stat structure
// and calculates avg. monthly rainfall, total
// annual rainfall, annual highest and lowest temps
// and the months they occurred and the avg montly temp/
// using the computed avg of all months
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
void holdHigh(int [] ,int);
enum Month {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC};
//function prototype for displayMonth
void displayMonth(int);
struct WeatherStats
{
float rainFall; //total rainfall by month
float highTemp; //high temp for month
float lowTemp; //low temp for month
float avgTemp; //avg temp for month
};
//function prototype for data getData
void getData(WeatherStats[], int);
void getMonth(int);
int main()
{
const int NUM_MONTHS = 12; //number of months
WeatherStats currentYear[NUM_MONTHS]; // array of WeatherStats
//Month currentMonth; //define enum for type Month
getData(currentYear, NUM_MONTHS); //function call to getData
system("PAUSE");
}
void getData(WeatherStats currentMonth, int theMonth)
{
WeatherStats tempWeatherStats[theMonth]; //temp for holding
structure variables
for (int x=0;x < theMonth; x++)
{
cout << "Please enter the rainfall for ";
displayMonth(theMonth);
cout <<": ";
cin >> tempWeatherStats[x].rainFall;
cout << "Please enter the high temperature for ";
displayMonth(theMonth);
cout <<": ";
cin >> tempWeatherStats[x].highTemp;
cout << "Please enter the low temperature for ";
displayMonth(theMonth);
cout <<": ";
cin >> tempWeatherStats[x].lowTemp;
tempWeatherStats[x].avgTemp = (tempWeatherStats[x].highTemp +
tempWeatherStats[x].lowTemp)/2;
}
}
//function to display month name
void displayMonth(int month)
{
switch(month)
{
case JAN :cout << "January";
break;
case FEB :cout << "February";
break;
case MAR :cout << "March";
break;
case APR :cout << "April";
break;
case MAY :cout << "May";
break;
case JUN :cout << "June";
break;
case JUL :cout << "July";
break;
case AUG :cout << "August";
break;
case SEP :cout << "September";
break;
case OCT :cout << "October";
break;
case NOV :cout << "November";
break;
case DEC :cout << "December";
break;
}
}
When I compile this code, I'm getting
[{Linker error] undefined reference to 'getData(WeatherStats*,int)'
I'm not sure what is causing the error.
Thanks
Art
// This program creates a weather stat structure
// and calculates avg. monthly rainfall, total
// annual rainfall, annual highest and lowest temps
// and the months they occurred and the avg montly temp/
// using the computed avg of all months
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
void holdHigh(int [] ,int);
enum Month {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC};
//function prototype for displayMonth
void displayMonth(int);
struct WeatherStats
{
float rainFall; //total rainfall by month
float highTemp; //high temp for month
float lowTemp; //low temp for month
float avgTemp; //avg temp for month
};
//function prototype for data getData
void getData(WeatherStats[], int);
void getMonth(int);
int main()
{
const int NUM_MONTHS = 12; //number of months
WeatherStats currentYear[NUM_MONTHS]; // array of WeatherStats
//Month currentMonth; //define enum for type Month
getData(currentYear, NUM_MONTHS); //function call to getData
system("PAUSE");
}
void getData(WeatherStats currentMonth, int theMonth)
{
WeatherStats tempWeatherStats[theMonth]; //temp for holding
structure variables
for (int x=0;x < theMonth; x++)
{
cout << "Please enter the rainfall for ";
displayMonth(theMonth);
cout <<": ";
cin >> tempWeatherStats[x].rainFall;
cout << "Please enter the high temperature for ";
displayMonth(theMonth);
cout <<": ";
cin >> tempWeatherStats[x].highTemp;
cout << "Please enter the low temperature for ";
displayMonth(theMonth);
cout <<": ";
cin >> tempWeatherStats[x].lowTemp;
tempWeatherStats[x].avgTemp = (tempWeatherStats[x].highTemp +
tempWeatherStats[x].lowTemp)/2;
}
}
//function to display month name
void displayMonth(int month)
{
switch(month)
{
case JAN :cout << "January";
break;
case FEB :cout << "February";
break;
case MAR :cout << "March";
break;
case APR :cout << "April";
break;
case MAY :cout << "May";
break;
case JUN :cout << "June";
break;
case JUL :cout << "July";
break;
case AUG :cout << "August";
break;
case SEP :cout << "September";
break;
case OCT :cout << "October";
break;
case NOV :cout << "November";
break;
case DEC :cout << "December";
break;
}
}