Skip to content

Instantly share code, notes, and snippets.

@danvas
Created October 13, 2011 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danvas/1285534 to your computer and use it in GitHub Desktop.
Save danvas/1285534 to your computer and use it in GitHub Desktop.
C++ code that calculates compound interests. (Exercise from Deitel & Deitel)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
for (int interest = 5; interest <=10; interest++)
{
double amount = 1000.00;
cout << "Interest Rate: " << interest << "%"
<< "\nYear" << setw(21) << "Amount on deposit" << endl;
cout << fixed << setprecision(2);
for (int year = 1; year <= 10; year++)
{
amount *= ( 1 + (static_cast<double>(interest)/100) );
cout << setw(4) << year << setw(21) << amount << endl;
}
cout << "\n" << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment