I have used this board once before and it was very helpful especially when I was blinded by the obvious so I thought I would ask to see if I have my loops back wards or incorrect. I am trying to build a program that displays a loan table for a 1000 loan for each interest rate depending on what you select to start with and end with along with a step size. The number of months is 30-72 incementing by 6 horizontally with the apr incrementing but the step size vertically like
apr 30 36 42 48 54 60 66 72
5.5 35.53 35.53 4951639 bunch a mumbo jumbo followed by 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000
6.0 35.75 35.75 Followed by the same mumbo jumbo and so on to it reaches its apr end
It seems to be getting the apr each time and calculating using the function but does nothing with the months and all the mumbo jumbo I have no clue. I have included the code and any guidance of where I have gone wrong would be helpful.
Code:#include <math.h> #include <stdio.h> # define mbegin 30 #define mlimit 72 #define mstep 6 /* Function protoype */ double loan (double p, double apr, int m, double c); int main(void) { double p = 1000; double aprstart = 0; double aprend = 0; double apr =0; double step = 0; int m = 0; double c = 0; printf("\n"); printf("\n"); printf(" Big Deal Autos\n"); printf(" Auto Loan Program\n"); printf(" By James Alexander"); printf("\n"); printf("\n"); printf("What is the starting Apr?\n"); scanf("%lf",&aprstart); printf("What is ths ending Apr?\n"); scanf("%lf",&aprend); printf("What is the APR step size?\n"); scanf("%lf",&step); apr = aprstart; printf("\n"); printf("\n"); printf("APR 30 36 42 48 54 60 66 72\n"); printf("\n"); for (m = mbegin; m <= mlimit; m += mstep) { while (apr != aprend + step) { printf("%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f",apr, loan(p, apr, m, c)); printf("\n"); apr = apr + step; } } } double loan(double p, double apr, int m, double c) { double r = (apr / 12) * 0.01; double a = p * r; double b= 1-(pow(1+r,-m)); c= a / b; return (c); }