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");
printf("please enter what your principal is \n");
scanf("%f",&principal);
printf("What is your interest rate?");
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();
}