Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 5.14 Modified Compound-Interest Program
- Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
- Visual Studio Community 2019 */
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- int main() {
- cout << fixed << setprecision(2);
- double startingPrincipal{ 1000.00 }; // initial amount before interest
- for (double rate{ .05 }; rate <= .1; rate += .01) {
- double principal{ startingPrincipal };
- cout << "\n\nInitial principal: " << principal << endl;
- cout << " Interest rate: " << rate << endl;
- cout << "\nYear" << setw(20) << "Amount on deposit" << endl;
- // calculate amount on deposit for each of ten years
- for (int year{ 1 }; year <= 10; year++) {
- // calculate amount on deposit at the end of the specified year
- double amount = principal * pow(1.0 + rate, year);
- // display the year and the amount
- cout << setw(4) << year << setw(20) << amount << "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment