oopss i still have a problem!!.. What's wrong with my code?

main()
{

int a[4];
int b[4];
int counter,sum=0;

cout<<"JANUARY";
for(counter=0;counter<4;counter++)
{
cout<<"Numbers of Rainfall:";
cin>>a[counter];
}

for(counter=0;counter<4;counter++)
{
sum+=a[counter];
}

cout<<"The numbers of rainfall in the first month"<<sum<<endl;

cout<<FEBRUARY;
for(counter=0;counter<4;counter++)
{
cout<<"Numbers of Rainfall";
cin>>b[counter];
}

for(counter=0;counter<4;counter++)
{
sum+=b[counter];
}

cout<<"The numbers of rainfall in the second month"<<sum<<endl;

getch();
return 0;
}

now my aim is to add all the values of first month and then print it. and same as the second month.(add all the values of second month and then print it). And when i run the program and then i put a values in the first month and its working fine but my problem is in second month because after i put a values in second month, the output of 1st month will add to the values of second month.

ex.
JANUARY
Numbers of Rainfall:4
Numbers of Rainfall:3
Numbers of Rainfall:2
Numbers of Rainfall:1

The numbers of rainfall in the first month 10

FEBRUARY
Numbers of Rainfall:5
Numbers of Rainfall:4
Numbers of Rainfall:3
Numbers of Rainfall:2

The numbers of Rainfall in Second month 24

now i need help on the second month on how to print the second month without adding the first month..?

Sorry i'm a newbie programmer but i'm studying hard. thanks guys..

You need int a[4] and int b[4] for every month, something like:

int a[12][4];
int b[12][4];

Just put sum = 0; before starting to add the second month rainfalls.

Please read this and make sure to use code tags when posting code from now on

EDIT: sweeya was faster, sorry.

thanks for helping guys! sorry for i don't use the code tags.. it won't be happen again..

Well as they already said reset sum to zero; next problem in month two would be, you forgot quotes " in cout, and I'm assuming the lack of int before main() is a copy-paste oversight.
You could create a class that holds all of the months, extra info and functions that deal with them; if you've gotten that far in your studies, yet.

This article has been dead for over six months. Start a new discussion instead.