In: Computer Science
Choose one of the three following programs to do as your first program. You need to turn in a flowchart and program documentation with the .cpp program (this can be done within the program) and a copy of your output.
The Program I chose is :
#19. Monthly Payments
The monthly payment on a loan may be calculated by the following formula:
Payment= Rate × (1+Rate)N (1+Rate)N−1×L
Rate is the monthly interest rate, which is the annual interest rate divided by 12. (12 percent annual interest would be 1 percent monthly interest.) N is the number of payments, and L is the amount of the loan. Write a program that asks for these values then displays a report similar to:
Loan Amount:$10000.00
Monthly Interest Rate: 1%
Number of Payments: 36
Monthly Payment:$ 332.14
Amount Paid Back:$ 11957.15
Interest Paid:$ 1957.15
CODE FOR THE FOLLOWING PROGRAM:-
#include <iostream>
#include <cmath>    //for pow()
#include <iomanip>  //for setw() and setprecision()
using namespace std;
int main()
{
    //Declaration of variables
    float lAmount,rate,mPayment,totalAmount,totalInterest;
    int noOfPayments;
    
    //Asking user to input values
    cout<<"Enter the loan amount: \n";
    cin>>lAmount;
    cout<<"Enter the monthly Interest Rate: (input should be in %)\n";
    cin>>rate;
    rate=rate/100;
    cout<<"Enter number of payments: \n";
    cin>>noOfPayments;
    
    //calculating monthly payment
    mPayment=((rate*(pow(rate+1, noOfPayments)))/((pow(rate+1, noOfPayments))-1))*lAmount;
    
    //calculating total amount to be paid
    totalAmount=mPayment*noOfPayments;
    
    //calculate amount of interest paid
    totalInterest=totalAmount-lAmount;
    
    //Printing the Report
    //Setw and setprecision are used for formatting
    cout << "Loan amount:            $" << setprecision(2) << fixed << setw(5) << lAmount << endl;
    cout << "Monthly Interest Rate:  " << setprecision(0)<<rate*100 << "%" << endl;
    cout << "Number of Payments:     " << noOfPayments << endl;
    cout << "Monthly Payment:        $" << setprecision(2) << fixed << setw(5) << mPayment << endl;
    cout << "Amount Paid Back:       $" << setprecision(2) << fixed << setw(5) << totalAmount << endl;
    cout << "Interest Paid:          $" << setprecision(2) << fixed << setw(5) << totalInterest << endl;
    return 0;
}
DOCUMENTATION FOR PROGRAM:-
 // FILE:         payment.cpp
   // TITLE:        Your title goes here
   // SUBMITTED BY:  Your Name goes here
   //                
   // FOR COURSE:  Course Name goes here  
   // DUE DATE:     ... 
   //
   // PURPOSE:
   // This program will calclulate the monthly payment on a loan
   //calcluated along with total amount paid and intrest paid
  
 
   // OVERALL METHOD:
   //The list of general task is:
   //Ask user to enter Loan Amount, Monthly Interest Rate and Number of Payments
    //calclulate Monthly Payment,Amount Paid Back and Interest Paid
    //Print Loan Amount, Monthly Interest Rate and Number of Payments
    //print Monthly Payment,Amount Paid Back and Interest Paid
   
    // INCLUDED FILES:
   //    iostream.h
   //    iomanip.h
   //    cmath.h
   
   // DATA FILES:
   //    none
FLOW CHART:-

SCREENSHOT OF THE PROGRAM AND SAMPLE OUTPUT:-

SAMPLE OUTPUT:-

HAPPY LEARNING