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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include <iostream> //for cin and cout
#include <iomanip> //for setprecision
#include <string>
using namespace std;
// The prupose of this program is to ask for a user to input a loan amout and interest rate percentage. The program then calculates the mothly payments
// and the total interest to be paid as well as the total amout left to be paid. Finally the program determines the average annual interest payemnts
// and the average annual interest rate. THis program is the same as the previous program except it uses void functions.
//create void functions
void welcome()
{
cout<<"Welcome to Christopher's Bank\n\n";
};
void header()
{
cout<<"Payment details:\n\n"
<<"Payment Number Interest Paid Remaning Balance\n"
<<"-------------- ------------- ----------------\n";
};
void getuserinput()
{
float loan, intrate;
cout<<"What is the amount of your loan? ";
cin>>loan;
cout<<"What is the interest rate? (Please enter as a %) ";
cin>>intrate;
};
void actualinterestrate()
{
float actualint, yearint, loan1;
actualint = yearint / loan1 * 100;
cout<<"actual interest rate: "<<actualint<<endl;
};
int main()
{
//Declare Variables
float loan, loan1, intrate, monthlypay, intpay, intrate2, totalint, yearint, actualint;
int paymentnum;
string another;
//Welcome message
welcome();
//Ask user to input loan amount and interest rate
getuserinput();
loan1 = loan;
//display total loan amount and monthly payments and calculate monthly payments
monthlypay = loan/20;
cout<<"\nMonthly payment on a loan of $"<<fixed<<setprecision(2)<<loan<<" is $"<<fixed<<setprecision(2)<<monthlypay<<"\n\n";
//calculate monthly payments and display them
header();
paymentnum = 0;
intrate2 = intrate / 100;
totalint=0;
yearint=0;
while(loan > 0)
{
intpay = loan * intrate2 / 12;
loan = loan + intpay - monthlypay;
paymentnum++;
if(loan<=0)
{
loan=0;
}
cout<<" "<<paymentnum<<" "<<intpay<<" "<<loan<<endl;
totalint= totalint + intpay;
};
//calcuate total interest paid for one year, the total interest and the actual interest rate
cout<<"\nTotal interest paid $"<<totalint<<endl;
yearint= totalint / paymentnum * 12;
cout<<"\n\nInterest paid for one year: $"<<yearint<<endl;
actualinterestrate();
//ask the user if they ahve another loan to calculate
cout<<"Do you have another loan to evaluate? (Y or y for yes, any other input for no) ";
cin>>another;
if(another == "Y" || another == "y")
{
return main();
}
else
{
cout<<"It was a pleasure doing business with you.\n"
<<"Anytime you need a loan think of <Christopher's Bank>\n\n";
system("pause");
return(0);
}
}
|