I can see a few reasons it won't compile
in line 13:
int years, // To hold each year
you've already declared years in line 6, and if you hadn't you should still end the statement with a semicolon ";"
line 17:
const int MAX_YEARS = years;
don't think you can assign a variable int to a constant.
in fact I think that's the defining characteristic of constants, you have to assign a constant value to them, compile time. It can't be reassigned in runtime.
in lines 23 and 27:
1 2 3 4 5 6 7 8
|
for (int counter = 0; counter < years; counter++)
{
// Variables
int number, // To hold each number
total = 0; // Accumulator, initialized with 0
// Constant for the number of numbers
const int MAX_NUMS = 12;
|
you're declaring variables within a for loop.. you can see why this won't work.
I think what you want is an array like
float monthly_rainfall[12];
I'm assuming you know how to access elements of an array, so after declaring the array we can start a for loop and use the "counter" as the [] argument:
1 2 3 4 5 6 7 8
|
for (int counter = 0; counter < 12; counter++)
{
cout << "Rainfall for the month: ";
cin >> number; // this also must be declared at top of main()
monthly_rainfall[counter] = number;
total += number;
...
}
|
then you can do stuff like get the average after they've all been entered.
edit: also should some of this stuff be in float instead of int?
or are all rainfall amounts going to be integers? that wouldn't make much sense.