negative struct output

I'm trying to write a general struct practice code, but the output is always negative. can anyone spot what I'm doing wrong?

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
57
58
#include <iostream>
using namespace std;
const int 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.
Topic archived. No new replies allowed.