garryhtreez

5.14

Nov 13th, 2020 (edited)
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. /* 5.14 Modified Compound-Interest Program
  2.    Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  3.    Visual Studio Community 2019  */
  4.  
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <cmath>
  8.  
  9. using namespace std;
  10.  
  11. int main() {
  12.    cout << fixed << setprecision(2);
  13.  
  14.    double startingPrincipal{ 1000.00 }; // initial amount before interest
  15.    for (double rate{ .05 }; rate <= .1; rate += .01) {
  16.       double principal{ startingPrincipal };
  17.       cout << "\n\nInitial principal: " << principal << endl;
  18.       cout << "    Interest rate:    " << rate << endl;
  19.       cout << "\nYear" << setw(20) << "Amount on deposit" << endl;
  20.  
  21.       // calculate amount on deposit for each of ten years
  22.       for (int year{ 1 }; year <= 10; year++) {
  23.          // calculate amount on deposit at the end of the specified year
  24.          double amount = principal * pow(1.0 + rate, year);
  25.  
  26.          // display the year and the amount
  27.          cout << setw(4) << year << setw(20) << amount << "\n";
  28.       }
  29.    }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment