# Thread: Making interest rate program in C

1. ## Making interest rate program in C

In my effort to become a software developer, I am faced with the project (more likely than not simple to the experience) where I must determine the monthly payment of a loan
Obviously to determine the monthly payment, the equation is :

rate*(1+rate)^n
----------------------------------*L
((1+rate)^n-1)

rate = the monthly interest
n = # of payments
l = loan amount

I am stumped as how to include the exponent into the code. obviously cmath is to be used:

let me give you what i have done, it is actually not much, as none of the MATH has actually been done:
Code:
```#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main ()
{
int loan; // Loan amount taken out
int payments; // Number of payments as well as exponent
int interest; // monthly interest rate
int result; // monthly payment
bool notValid;

cout <<"Use this program to";
cout <<"determine monthly interest - enter loan amount\n";
do {
notValid =false;
cin>>loan;

if (loan < 10 || loan> 999999)
{
cout <<"\n The loan amount must";
cout <<"be between \$10 and \$999,999.99";
notValid=true;
}
}while (notValid);

cout <<"\n Enter number of monthly payments:";
do {
notValid =false;
cin>>payments;

if (payments < 10 || payments> 360)
{
cout <<"\n The monthly payments must";
cout <<"be between 12 and 360 months";
notValid=true;
}
}while (notValid);
}```
-----------
All i have included are two of the inital equations ( I still have to ask how much the interest is, which isnt a problem) and the validation problem aka making sure the user inputs are between the specificed range.

Im not asking for this to be written for me, obviously I have to do that - which I want to - i want to learn the process of how this is done, and maybe if there is a more efficent way to doing this. Also note that this is a structed programming intro course to C, so for any explanations - please try to keep it in those terms.

I also have to present this information back to the user, but Im pretty sure how to do that. Any help would be great

you can respond here or my aim is chikkennn

2. I am stumped as how to include the exponent into the code. obviously cmath is to be used:
In C:
Code:
```#include <math.h>
int x = pow(2, 8);  /* 2 to the power of 8 = 256 */```
In C++:
Code:
```#include <cmath>
int x = pow(2, 8);  /* 2 to the power of 8 = 256 */```
dwk

3. I believe in C++ it would have to be "pow((double)2, 8)" or "pow(2.0, 8)" to keep the compiler happy.

4. Sorry, I was so concerned about the header file that I missed that . . . .

5. A quick google indicates that both variables are supposed to be doubles: http://www.hmug.org/man/3/pow.php

6. But on the other hand, with simple algebra, your problem simplifies to rate * (1+rate), so why bother?