1. ## Calculation Question

So, while I think I am getting better (I THINK), one thing that will always stump me in programming are equations. More specifically, longer mathematical equations. Right now, I am making a "Loan Calculator". Basically, it just uses a switch in another function, returns the values to the main function and it prints it out.

Unfortunately, given the formula I need to use, I can't figure out how to incorporate it in into a loop, as well I can't really understand the equation, even though it explains it.. (I'm retarded when something involves complicated looking math.)

Here's my code thus far. I need to make a loop do two things::

--Loop to output for however many months entered and the information for each month (Posted guess at end of post) This isn't my major issue however.

--Figure out how exactly the equation works and use it in the loop (My major issue).
----EQUATION:: payment =.......... ........principal x rate....
.................... .... .......... 1 - ( (1+rate) to the power (-m) ) )

--I'v also got no idea what a "Principal" refers to.

Rate = annual interest rate
M = number of months

(I know it's not done but. I can't really do much unless I figure this calculation stuff out
Code:
```#include <stdio.h>
#include <math.h>

int swit(void);

int main(void)
{

int choice;

printf("1. Enter Principal\n2. Enter Annual Interest Rate\n3. Enter Duration of the loan\n4. Calculate Loan Payment\n5. Display Loan Repayment Table\n\n");

printf("Month::Old Balance::Payment::Interest::Principal::New Balance");

getchar();
getchar();
return 0;
}

{
int choice;
int princ;
int ir;
int dur;
int calc;

while ((choice = getchar()) != 0)
{

switch (choice)
{

case '1' :

princ = getchar();
break;
case '2' :

ir = getchar();
break;
case '3' :

dur = getchar();
break;
case '4' :

break;
case '5' :

break;
default :
printf("You entered an invalid choice.\nPlease pick 1-5 or use 0 to exit the program\n");
break;
}
}
return choice;

}```
So far my guess is going to be something like this for the loop

for (i = 1; i < months; i++). However. I am somewhat confused on how to do the calculations themselves (This is the most major thing I need help with. How exactly, after each calculation, I am supposed to re-calculate for the loop.

Any help would be greatly appreciated. I am absolutely useless when it come's to math. 2. Code:
```for(i = 0;i < months;++i)
principal = principal * (1 + (rate / 12));``` 3. Originally Posted by itsme86 Code:
```for(i = 0;i < months;++i)
principal = principal * (1 + (rate / 12));```
If they input 36 for however many months they put in for time to pay, than I assume that means this can easily be altered by dividing rate / 36, rather than 12? 4. You don't need to change it. The division by 12 is just to change the annual interest rate to a monthly calculation. If the annual interest rate is, let's say, 6%, the monthly interest you pay should only be 6% / 12, or 0.5%, per month. 5. Originally Posted by itsme86 You don't need to change it. The division by 12 is just to change the annual interest rate to a monthly calculation. If the annual interest rate is, let's say, 6%, the monthly interest you pay should only be 6% / 12, or 0.5%, per month.
Alright thanks alot. Helped me out big time. And looked like what I thought the loop would be was only slightly off. Thanks again ^^

So i'v not got a new question about the calculation.

Using this:

Code:
```    for(int i = 0;i < months; ++i)
{
printf(" new balance: %d ", newbalance);
principal = principal * (1 + (rate / 12));
buffer=oldbalance-principal;
newbalance=buffer;
}```
Given values for each variable, the program does as it should for the most part, however. I am missing one small thing. The "rate" variable doesn't seem to change anything. even given the variable a value, won't change the value. It will just consistently subtract 500 each time until the loop finishes, depending on the months entered. Anything i'm missing here? Popular pages Recent additions 