Can't Firgure out the error!!

// The program actually runs, but stops after statInfo() function is called in main.




#include <iostream>

using namespace std;

const int INDEX=12;

struct Stats
{
double rainfall;
double highTemp;
double lowTemp;
double avgTemp;
};

Stats data[INDEX];

const string Month [INDEX] = {"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};

void statInfo();
void rainAverage();
void highestTemperature();
void lowestTemperature();
void temperatureAverage();

int main(int argc, const char * argv[])
{
statInfo();
cout << '\n';
rainAverage();
highestTemperature();
lowestTemperature();

return 0;
}





//***********************************************************
// This function asks the user for the information of *
// amount of rain, highest temp. and lowest temp. it also *
// calculates the average temp. *
//***********************************************************



void statInfo()
{
for (int i=0; i<=INDEX; i++)
{
cout << "Data for " << Month[i] << ":" << endl; [b][b] //HERE IS THE ERROR in green (Thread1: EXC_BAD_ACCESS (code=1, address 0xffffffffffffffffffffe9)
cout << "Rainfall (mm):";
cin >> data[i].rainfall;
cout << "High Temperature (F): ";
cin >> data[i].highTemp;
cout << "Low Temperature (F): ";
cin >> data[i].lowTemp;
data[i].avgTemp = data[i].highTemp/data[i].lowTemp;
cout << endl;
}


}






//***********************************************************
// This function calculates the average rain for the year *
//***********************************************************

void rainAverage()
{
double rainAvg=0;
for (int i=0; i<=INDEX; i++)
{
rainAvg += data[i].rainfall;
}
rainAvg=rainAvg/INDEX;
cout << "The average rainfall for the year has been: " << rainAvg << "mm";
}




//***********************************************************
// This function calculates the highest temperature for the *
// year and the month in which it took place *
//***********************************************************

void highestTemperature()
{
int highestTemp=0;
string highestMonth;
for (int i=0; i<=INDEX; i++)
{
if (data[i].highTemp>highestTemp)
{
highestTemp=data[i].highTemp;
highestMonth=Month[i];
}
}
cout << "Highest Temperature of the year: " << highestMonth << " - " << highestTemp << "F";
}



//***********************************************************
// This function calculates the highest temperature for the *
// year and the month in which it took place *
//***********************************************************

void lowestTemperature()
{
int lowestTemp=141;
string lowestMonth;
for (int i=0; i<=INDEX; i++)
{
if (data[i].highTemp<lowestTemp)
{
lowestTemp=data[i].highTemp;
lowestMonth=Month[i];
}
}
cout << "Highest Temperature of the year: " << lowestMonth << " - " << lowestTemp << "F";
}




//******************************************************************
// This function calculates the average temperature for the year *
//******************************************************************

void temperatureAverage()
{
double tempAvg=0;
for (int i=0; i<=INDEX; i++)
{
tempAvg += data[i].avgTemp;
}
tempAvg=tempAvg/INDEX;
cout << "Average temperature for the year: " << tempAvg << "F";
}
Last edited on
closed account (10oTURfi)
Use [ code][/code] tags and please save us some reading and tell what the error says...
Yeah, [code][/code] tags make everything so much easier to read....

But anyways:
for (int i=0; i<=INDEX; i++)
The <= should just be < .
Topic archived. No new replies allowed.