From c4471a5113fdec03980f450eea6b839006886b4c Mon Sep 17 00:00:00 2001 From: Jesus Hilario Hernandez Date: Mon, 10 Sep 2018 17:46:41 -0500 Subject: [PATCH] modified --- .../Programming Challenges/19.cpp | 41 ++++++++++--------- .../Programming Challenges/20.cpp | 17 ++++---- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Chapter-3-Expressions-and-Interactivity/Review Questions and Exercises/Programming Challenges/19.cpp b/Chapter-3-Expressions-and-Interactivity/Review Questions and Exercises/Programming Challenges/19.cpp index 2e29dd4..4ab5fa8 100644 --- a/Chapter-3-Expressions-and-Interactivity/Review Questions and Exercises/Programming Challenges/19.cpp +++ b/Chapter-3-Expressions-and-Interactivity/Review Questions and Exercises/Programming Challenges/19.cpp @@ -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 @@ -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? %"; @@ -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 * @@ -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; } diff --git a/Chapter-3-Expressions-and-Interactivity/Review Questions and Exercises/Programming Challenges/20.cpp b/Chapter-3-Expressions-and-Interactivity/Review Questions and Exercises/Programming Challenges/20.cpp index 6caa919..4a1d64d 100644 --- a/Chapter-3-Expressions-and-Interactivity/Review Questions and Exercises/Programming Challenges/20.cpp +++ b/Chapter-3-Expressions-and-Interactivity/Review Questions and Exercises/Programming Challenges/20.cpp @@ -30,9 +30,10 @@ * place of precision. Use a named constant for pi. * * Jesus Hilario Hernandez -* August 3rd 2018 +* Sept 4th 2018 * -*********************************************************#include +********************************************************************/ +#include #include // pow() #include using namespace std; @@ -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; }