Part 1 (separate solution): You don\'t need to round to the nearest penny, or al
ID: 3736258 • Letter: P
Question
Part 1 (separate solution):
You don't need to round to the nearest penny, or align the output into a table. So, this is OK too:
Please enter loan amount: 10000
Please enter annual interest rate as percent: 12
Please enter number payments: 36
Loan Amount: $10000
Monthly Interest Rate: 1
Number of Payments: 36
Monthly Payment: $332.143
Amount Paid Back: $11957.2
Interest Paid: $1957.15
Explanation / Answer
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
double findPaymentAmount( double loanAmount, double annualInterestRate, double numberOfPayments);
double findMonthlyInterestRate( double annualInterestRate);
double findPaymentAmount( double loanAmount, double annualInterestRate, double numberOfPayments){
double rate = findMonthlyInterestRate(annualInterestRate)/100;
double N = numberOfPayments;
double L = loanAmount;
double paymentAmount;
//payment = ((rate * (1+rate)^N) / ((1+Rate)^N - 1)) * L
paymentAmount = ((rate * pow((1+rate),N)) / ( pow((1+rate),N )- 1)) * L ;
return paymentAmount;
}
double findMonthlyInterestRate(double annualInterestRate){
return annualInterestRate/12;
}
int main(){
double loanAmount, annualInterestRate, numberOfPayments, paymentAmount;
cout << "Please enter loan amount: " <<endl;
cin >> loanAmount;
cout << "Please enter annual interest rate as percent: " <<endl;
cin >> annualInterestRate;
cout << "Please enter number payments: " <<endl;
cin >> numberOfPayments;
cout << "Loan Amount: " << loanAmount << endl;
cout << "Monthly Interest Rate: " << findMonthlyInterestRate(annualInterestRate) << endl;
cout << "Number of Payments: " << numberOfPayments << endl;
paymentAmount = findPaymentAmount( loanAmount, annualInterestRate, numberOfPayments);
cout << "paymentAmount : " << paymentAmount <<endl;
cout << "Amount Paid Back : " << paymentAmount * numberOfPayments <<endl;
cout << "Interest Paid : " << paymentAmount * numberOfPayments - loanAmount <<endl;
}