# Thread: got my compound interest calc working but it has an array error after completing!

1. ## got my compound interest calc working but it has an array error after completing!

I wrote a simple program to compound interest over 25 years. interest compounded monthly. here is the code. everything works great it prints out all information but freezes after making all calcs. anyone able to see were I have strayed?
Code:
```/* Program 5.2 from PTRTUT10.HTM   6/13/97 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct database {   /*defines struct that will be 1 year and contain 12 months*/
float month[12];
};
int main(){
struct database year[25];     /*forms 25 structures which will be equal to 25 year I want to track*/
struct database *point[25];   /*forms pointers that I havent used yet but want around in case I decide to create more functions*/

int x,y; /*x and y will be used for counters in the loops*/
float interest,lastvalue, principal;  /* The main variables for our program*/
for(x=1;x<=25;x++){ /*assigns points to corresponding structures again for future use*/
point[x]=&year[x];
}
for(x=1;x<=25;x++){ /*loop for clearing all variables and setting to zero will move to a seperate function once things are operating properly*/
for(y=1;y<=12;y++){
year[x].month[y]=0;
printf("year %d month %d value %f \n",x,y,year[x].month[y]);
}
}
system ("cls");
scanf("%f",&principal);
scanf("%f",&interest);
interest=(interest/100) + 1;
lastvalue=principal;
for(x=1;x<=25;x++){
for(y=1;y<=12;y++){ /*main loop to compound the interest*/
year[x].month[y]=lastvalue*interest;
lastvalue=year[x].month[y];
printf("year %d month %d value %f \n",x,y,year[x].month[y]);
}
}
getchar();
}```

2. Arrays start at zero, not one. This means a for loop over 25 items should look like this:
Code:
`for (x=0; x < 25; x++)`
Same deal for 12 items obviously.

To get furthur help, please first fix up the indentation of that code so that it isn't going left and right all over the place. Replace tabs with a fixed number of spaces before posting. Reading the FAQ or wiki about indentation might help you.

3. And same with months. Last slot in arrau declared as months[12], is months[11] (first is months[0])