// Robert A. Simpson

// CS132: Programming in C++

// unit 2

// sept. 9 1997

//

// This program will compute compound interest using

// variables you input.

// This will tell the computer what files I need to run this program.

#include <iostream.h>

#include <iomanip.h>

#include <math.h>

// This is the start of the main program.

main ()

{

// I don't know what this does. I was just told that it will tell

// the computer to print all numbers to two decible places.

// In other words monkey see monkey do!

cout.setf(ios::showpoint|ios::fixed|ios::floatfield);

cout.precision(2);

// Declare all variables.

double loan; // amount of loan

int year ; // number of years

double rate; // interest rate

double payment=0; // total amout paid on loan

double interest=0; // interest per month

double t_loan=0; // total loan amount

double m_rate=0; // monthly rate

double balance=0; // loan balance

int month=0; // years times 12

int paidonloan=0; // what was acctually paid against loan balance

int t_rate=0; // total interest rate

int count=0; // used for a counter see while statement

int countmonth=0; // used for counter so I can use month for computation

// ask for inputs

cout << "Enter amount of loan: ";

cin >> loan;

cout << "Enter number of years: ";

cin >> year;

cout << "Enter interest rate: ";

cin >> rate;

cout << " " << endl; // prints a blank line

cout << " " <<endl; // I used it to make the print out look neater

// compute interest

month=year*12;

// countmonth needs to be equaled to month so my chart will

// print the correct number of months

countmonth = month;

balance=loan*100;

m_rate = rate/100/12;

//print heading

cout << setw(10) << "MONTH" << setw(15) <<"PAYMENT";

cout << setw(10) <<"INTEREST" << setw(20) <<"PAID ON LOAN";

cout << setw(10)<<"BALANCE" << endl;

cout << " " << endl; // to print a blank line

// while statement I will use this to make my chart

while(count < countmonth){

// computations of loan payment

interest = balance*m_rate;

payment = balance/month;

paidonloan = payment-interest;

balance=balance-paidonloan;

t_rate=t_rate+interest;

t_loan=t_loan+payment;

// prints results

cout << setw(10) << count << setw(15) << (payment/100.0+0.005);

cout << setw(10) << (interest/100.0+0.005) ;

cout << setw(20) << (paidonloan/100.0+0.005) << setw(10) << (balance/100.0+0.005);

cout << endl;

// I used a seperate counter because month is used for my computation

count=count+1; // adds 1 to counter

month=month-1; // subtracts 1 from month

} // end of while loop

// prints the last line of chart

cout <<setw(10) << count <<setw(15) << (balance/100.0+0.005) << setw(10)<< "0";

cout <<setw(20) << (balance/100.0+0.005) <<setw(10) <<"0" << endl;

// prints totals

cout << "TOTAL INTEREST: " << (t_rate/100.0) << endl;

cout <<"TOTAL PAYMENT: " <<( (t_loan+balance)/100.0) << endl;

return 0;

}

back

Home Page