1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
void welcome (int &ans);
void loan_info (float &amt, float &rate);
float payment (float bal, float m_rate, int n_payments);
float power (int exponent, float number);
int main ()
{
float loan_amt, apr, loan_payment;
int n_payments, choice;
system ("color 0A"); //set fonts to green
welcome(choice); //call welcome module
loan_info (loan_amt, apr); //call loan_info module
if (choice==1)
for(n_payments=36; n_payments <= 60; n_payments +=12)
{
loan_payment = payment (loan_amt, apr, n_payments); //call payment module
cout <<endl<<"Your monthly payment for "<<n_payments<<" months will be: $" <<loan_payment;
}
else
for(n_payments=180; n_payments <= 360; n_payments +=180)
{
loan_payment = payment (loan_amt, apr, n_payments); //call payment module
cout <<endl<<"Your monthly payment for "<<n_payments<<" months will be: $" <<loan_payment;
}
return 0;
}
/********************* DISPLAY WELCOME MSG ********************/
void welcome (int &ans)
{
do
{
cout<<"Welcome, This program will calculate monthly loan payments."<<endl<<endl;
cout<<"Would you like to calculate payments for a home loan or car loan?"<<endl<<endl<<endl;
cout<<"Enter 1 for car loan Enter 2 for home loan:\n>>> ";
cin>>ans;
if ((ans!=1 ) && (ans!=2))
{
system("CLS");
cout<<"I DID NOT RECOGNIZE YOUR INPUT PLEASE SELECT 1 OR 2!"<<endl<<endl;
}
}
while ((ans!=1 ) && (ans!=2));
}
/********************* GET LOAN INFORMATION *******************/
void loan_info (float &amt, float &rate)
{
cout<<"Please enter the amount of the loan: ";cin>>amt;
cout<<"Please enter the annual percentage rate: ";cin>>rate;
}
/****************** CALCULATE MONTHLY PAYMENT *****************/
float payment (float bal, float m_rate, int months)
{
float bill;
bill=1.0;
m_rate = m_rate/100/12;
bill = (bal * m_rate) / (1 - (power (-months,(1 + m_rate))));
return(bill);
}
/*******************************************************************/
float power (int exponent, float number)
{
float result;
int i;
result = 1.0;
for (i=0; i< abs (exponent); i++) result *= number;
if (exponent > 0)
return (result);
else
return (1.0 / result);
}
|