Skip to content

Commit

Permalink
modified
Browse files Browse the repository at this point in the history
  • Loading branch information
jesushilarioh committed Sep 10, 2018
1 parent 429953d commit c4471a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* 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
Expand Down Expand Up @@ -33,16 +34,16 @@ int main()
// Constant
const int ONE = 1,
HUNDRED = 100;

// Variables
int N;

float Rate,
L,
Payment,
amount_paid_back,
interest_paid;

// Ask the user for Rate, number of paymets, and amount of the loan
cout << endl;
cout << "What is interest rate of the loan? %";
Expand All @@ -51,18 +52,18 @@ int main()
cin >> L;
cout << "Number of payments? ";
cin >> N;

// Calculation
Rate /= HUNDRED; // 4.25% == .0425
// Payment = [Rate * (1 + Rate)^N / ((1 + Rate)^N - 1)] * L
Payment = ((Rate) * pow(ONE + (Rate), N) / (pow(ONE + (Rate), N) - ONE)) * L;

Rate *= HUNDRED; // .0425 == 4.25

amount_paid_back = N * Payment;

interest_paid = (N * Payment) - L;

// Display
/************************************************
* Loan Amount: $ 10000.00 *
Expand All @@ -72,30 +73,30 @@ int main()
* Amount Paid Back: $ 11957.15 *
* Interest Paid: $ 1957.15 *
************************************************/

cout << setprecision(2) << fixed << right << endl;

cout << "Loan Amount: $";
cout << setw(10) << L << endl;

cout << "Monthly Interest Rate: ";
cout << setw(10) << Rate << '%' << endl;

cout << "Number of Payments: ";
cout << setw(10) << N << endl;

cout << "Monthly Payment: $";
cout << setw(10) << Payment << endl;

cout << "Amount Paid Back: $";
cout << setw(10) << N * Payment << endl;

cout << setw(10) << amount_paid_back << endl;
cout << "Interest Paid: $";
cout << setw(10) << (N * Payment) - L;

cout << setw(10) << interest_paid;
cout << endl << endl;


// Terminate Program
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
* place of precision. Use a named constant for pi.
*
* Jesus Hilario Hernandez
* August 3rd 2018
* Sept 4th 2018
*
*********************************************************#include <iostream>
********************************************************************/
#include <iostream>
#include <cmath> // pow()
#include <iomanip>
using namespace std;
Expand All @@ -42,32 +43,32 @@ int main()
// Constants
const float SLICE_AREA_SIZE = 14.125,
PI = 3.14159;
const int TWO = 2;
// Variables
float d, // Diameter
r, // Radius
Area,
num_of_slices;
// Ask the user for the diameter of the pizza in inches.
cout << endl;
cout << "What is the diameter of the pizza in inches? ";
cin >> d;
// Calculate the # of slices that may be taken from a pizza
// of that size
r = d / TWO; // Radius
Area = PI * pow(r, TWO);
num_of_slices = Area / SLICE_AREA_SIZE;
// Display a message telling the number of slices.
cout << setprecision(1) << fixed;
cout << "Number of slices = ";
cout << num_of_slices << endl;
cout << endl;
// Terminate Program
return 0;
}

0 comments on commit c4471a5

Please sign in to comment.