#include <iostream>
usingnamespace std;
constint NUMMONTHS = 3;
struct airport
{
int landed;
int departed;
int maxLanded;
int minLanded;
};
void main()
{
airport LAX[NUMMONTHS];
for (int i = 0; i < NUMMONTHS; i++)
{
cout << "enter the number of planes that landed for month " << (i + 1) << ".\n";
cin >> LAX[i].landed;
cout << "enter the number of planes that departed for month " << (i + 1) << ".\n";
cin >> LAX[i].departed;
cout << "enter the greatest number of planes that landed on a single day for month " << (i + 1) << ".\n";
cin >> LAX[i].maxLanded;
cout << "enter the least number of planes that landed on a single day for month " << (i + 1) << ".\n";
cin >> LAX[i].minLanded;
}
cout << "the average number of planes landed per month is " <<
(LAX[1].landed + LAX[2].landed + LAX[3].landed) / 3 << ".\n";
cout << "the average number of planes departed per month is " <<
(LAX[1].departed + LAX[2].departed + LAX[3].departed) / 3 << ".\n";
cout << "the total number of planes landed for the 3 months is " <<
(LAX[1].landed + LAX[2].landed + LAX[3].landed) << ".\n";
cout << "the total number of planes departed for the 3 months is " <<
(LAX[1].departed + LAX[2].departed + LAX[3].departed) << ".\n";
int minLandedYear = LAX[1].landed;
int minMonth = 1;
int maxLandedYear = LAX[1].landed;
int maxMonth = 1;
for (int j = 1; j < 3; j++)
{
if (LAX[j].landed < minLandedYear)
{
minLandedYear = LAX[j].landed;
minMonth = j + 1;
}
}
for (int j = 1; j < 3; j++)
{
if (LAX[j].landed > maxLandedYear)
{
maxLandedYear = LAX[j].landed;
maxMonth = j + 1;
}
}
cout << "the least number of planes landed for the 3 months was " << minLandedYear << ".\n";
cout << "this was during month " << minMonth << ".\n";
cout << "the greatest number of planes landed for the 3 months was " << maxLandedYear << ".\n";
cout << "this was during month " << maxMonth << ".\n";
}
LAX[3].departed
You are indexing out of bounds. Change (LAX[1].landed + LAX[2].landed + LAX[3].landed) (and other related summations) to count from 0 instead of 1.
int minLandedYear = LAX[1].landed; You probably want that to be int minLandedYear = LAX[0].landed;, and likewise for your other initializations.
JayhawkZombie, thank you so much, I don't know how I overlooked that. I never go out of bounds. I suppose I should sleep. Anyway, it worked and I appreciate it.