I've no idea if this is too newbie or generic for stackoverlflow. Apologies if that's the case, I don't intend to waste time.
I've just started working through C++ Primer Plus and I've hit a little stump. This is probably super laughable but:
const int MONTHS = 12;
const int YEARS = 3;
int sales[YEARS][MONTHS] = {0};
const string months[MONTHS] = {"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"
};
for (int year = 0; year < YEARS; year++)
{
for (int month = 0; month < MONTHS; month++)
{
cout << "Please enter year " << year + 1 << " book sales for the month of " << months[month] << ": \t";
cin >> sales[year][month];
}
}
int yearlyTotal[YEARS][3] = {0};
int absoluteTotal = 0;
cout << "Yearly sales:" << endl;
for (int year = 0; year < YEARS; year++)
{
cout << "Year " << year + 1 << ":";
for (int month = 0; month < MONTHS; month++)
{
absoluteTotal = (yearlyTotal[year][year] += sales[year][month]);
}
cout << yearlyTotal[year][year] << endl;
}
cout << "The total number of books sold over a period of " << YEARS << " years is: " << absoluteTotal << endl;
I wish to display the total of all 3 years. The rest of the code works fine: input is fine, individual yearly output is fine but I just can't get 3 years added together for one final total.
Sample data would be entering 1 for every option, to give me 3 totals of 12:
year 1: 12
year 2: 12
year 3: 12
The total number of books sold over a period of 3 years is: 12
The final 12 should obviously be 36.
I did have the total working at one point but I didn't have the individual totals working. I messed with it and reversed the situation. I've been messing with it for God knows how long.
Any idea guys? Sorry if this isn't the place!