### Exponent Substitution

I have to write a program that will calculate the monthly payment based on a total balance, APR, and finance period all of which are user inputs. My teacher gave us the equation payment = balance / (1 - (1 + interest)-n / interest). N is the number of months the finance period will last. Here's the catch; we are not allowed to use the math library to access exponents so I really have no clue what to do. He said something about using a loop but gave no specifics so I'm flying blind.
Create a function with parameters for a number and the exponent, then use a loop to multiply the number by itself however many times the exponent says.
Sorry, I'm not entirely sure how to write that.
Show us how far you got, and we can help you get further.
I've done nothing as far as the math but here's what I've written.

////////////////////////////////
// Keenan Brown //
// Lab 2 //
// banker //
// 27 September 2012 ///
////////////////////////////////////////////////////////////////////////
// This program will calculate monthly payments //
// based on the total balance, annual percentage rate, //
// and the how long payments will be made in months. //
////////////////////////////////////////////////////////////////////////

# include <iostream> // Needed for stream I/O

# include <cstdlib> // Needed for system command, "clear"

# include <iomanip> // Needed for fixed decimal position

using namespace std; // Simplifies cin and cout

int main()
{

///////////////////////////////
// Vraiable Declaration //
///////////////////////////////

float payment; // The calculated monthly payment

float balance; // The total amount to be financed

float apr; // The APR inputted by the user

float interest; // The monthly interest calculated from APR

int n; // The number of months to be financed

int choice; // The menu choice the user makes

system ("clear"); // System command to clear the screen

///////////////////////////////////
// User prompt and menu //
//////////////////////////////////

cout << "1. Calculate Loan Payments";

cout << "\n2. Quit" << "\n\t";

cin >> choice;

///////////////////
///////////////////

interest = apr / 12 / 100; // Math to calculate monthly interest from APR

if (choice == 1)
{

do
{

cout << setprecision(2) << fixed; // Sets all decimal points to 2 places

cout << "\n\nHow much are you financing?\n\t";

cin >> balance;

cout << "\n\nHow long is the finance period in months?\n\t";

cin >> n;

cout << "\n\nWhat is the APR for this finance?\n\t";

cin >> apr;

/////////////////////////////////////
// User prompt and storage //
/////////////////////////////////////

cout << "\nBalance: \$" << balance;

cout << "\nAPR: " << apr << "%";

cout << "\nMonthly interest: " << apr / 12 << "%";

cout << "\nTerm: " << n << " months";

cout << "\n\nCalculated monthly payment: \$" << payment;

/////////////////////////////////////////////////////
// Display of user inputs and calculation //
////////////////////////////////////////////////////

cout << "\n\nPress ENTER to continue.";

cin.get( );

cin.ignore (1, '\n');

/////////////////////////////////////////////////////////////////
// Pauses program until user chooses to continue //
/////////////////////////////////////////////////////////////////

}

while (choice = 1);

}

else if( choice == 2)
{

cout << "\n\nGood day.\n\n";

}

return 0;

}
Topic archived. No new replies allowed.