Server IP : 172.16.15.8 / Your IP : 52.14.6.41 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/cathomas/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
//------------------------------------------------------------------------ // Programming Assignment #1 // // Written by C A Thomas // September 2008 // // Purpose: To compute the monthly payment of an installment loan and // the balance remaining after half of the installments have // been made. Also, compute the total amount of interest paid // over the life of the loan. //----------------------------------------------------------------------- //------------------ Proprocessor Section ------------------------------- #include <iostream> #include <iomanip> #include <cmath> using namespace std; //----------------- Main Function --------------------------------------- int main () { //---------------- Variables and Constants ------------------------------ int numofpay, // number of monthly payments k; // half the number of payments float i, // annual interest rate loanam, // amount of loan payment, // monthly payment totalip, // total interest paid temp, // part of payment processing balance; // balance half way through //----------------- Input Phase ----------------------------------------- cout << "\n\n Welcome to the Loan Analysis Program!" ; cout << "\n\n Enter loan amount: " ; cin >> loanam; cout << "\n Enter annual interest rate (as a decimal): " ; cin >> i; cout << "\n Enter number of monthly payments: " ; cin >> numofpay; //---------------- Processing Phase ------------------------------------- temp = (1 + (i / 12)); k = numofpay / 2; payment = (pow(temp,numofpay)) / (pow(temp,numofpay) -1) * loanam * (i / 12); balance = payment * ((1 - pow(temp,(k-numofpay))) / (i / 12)); totalip = payment*numofpay-loanam; //--------------- Output Phase ----------------------------------------- cout << fixed << setprecision(2); // force fixed point format for floats cout << "\n\n ~~~~~~~~~~~ Loan Summary~~~~~~~~~~~\n " ; cout << "\n Annual Interest Rate: % " << i*100; cout << "\n Number of Monthly Payments: " << numofpay << endl; cout << "\n Loan Amount: $ " << setw(10) << loanam; cout << "\n Monthly payment: $ " << setw(10) << payment; cout << "\n Balance halfway through: $ " << setw(10) << balance; cout << "\n Total interest paid: $ " << setw(10) << totalip << endl; return 0; }