I am fairly new to C and have been working on this code for a few days now, trying to achieve a program that calculates a mortgage with compound interest.
I decided to play around with arrays instead of trying to display the results in a table, and they seem to be displaying my results as I want them to be.
However, I have played around far too much with the formulas/variables I made and just end up getting crazy results. I'm aiming to display one year of values at a time (12 lines), with three columns: amount to pay, amount paid and interest charged. The amount to pay should constantly be going down, amount paid going up originally then down as the 'to pay' goes down (and less interest should be charged because the amount to pay is less) and the interest charged should go down as the amount to pay goes down. I think that makes sense...sorry, you can tell how confused I've got!
If the mortgage is taken over several years, I tried to make it so that it would display a year at a time when '1' was pressed...which did work...but now it seems to drop out of the program.
Could you please have a look at my code and point me in the right direction? Many thanks!
//Only IO is required
void main ()
int amount, borrowed, payment, months, j, k, l=0, years, exit, mon;
float interest, topay, amountpaid, interestpaid,monthlypay,rollinterest,totalint;
//Declaring all variables, characters, integers, floats, arrays
printf("Welcome to the Mortgage Calculator \n\r\n\r");
printf("\n\r\n\r Please enter the amount you would like to borrow: \n\r (This amount should be greater than or equal to 1000) \n\r\n\r ");
scanf("%d", & amount);
while(amount <= 999);
printf("\n\r\n\r Over how many years do you wish to pay this amount: \n\r\n\r");
scanf("%d", & years);
printf("\n\r\n\r Please enter the applicable interest rate: \n\r");
scanf("%f", & interest);
while(interest >= 10);
printf("\n\r\n\r How much will your initial payment be: \n\r\n\r ");
scanf("%d", & payment);
while(payment >= amount);
printf("\t\t\t Mortgage Calculator \n\r");
printf("\t\t\t ******************* \n\n\r");
printf("Month Amount to pay Amount paid Interest Charged \n\r\n\r");
for(l = 0; l<12;l++)
borrowed = amount-payment;
topay[j] = borrowed - amountpaid[k];
months = years * 12;
rollinterest = (topay[j]/100)*interest;
monthlypay = topay[j] / months;
amountpaid[k] = monthlypay+rollinterest;
printf("\n %d \t %f \t %f \t %f",mon,topay[j],amountpaid[k],totalint[l]);
printf("\n\r\n\r You have paid %f this year \n",amountpaid[k]);
printf("\n You have %f of your mortgage left to pay \n",topay[j]);
printf("\n The total interest you have been charged this year is %f \n",totalint[l]);
printf("\nPlease enter 1 to continue! \n\r");