Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created October 17, 2012 07:48
Show Gist options
  • Save juanfal/3904266 to your computer and use it in GitHub Desktop.
Save juanfal/3904266 to your computer and use it in GitHub Desktop.
How long does it take (in months) to accumulate a debt of €100 starting with a debt of €50 and being charged with 2% each months?
// 02.Balance.cpp
// from Savitch
// How long does it take (in months) to accumulate a debt
// of €100 starting with a debt of €50 and being charged with
// 2% each months?
#include <iostream>
using namespace std;
// consts
const float STARTING_DEBT = 50.0;
const float MAXDEBT = 100.0;
const float INTRATE= 2;
int main( )
{
double balance = STARTING_DEBT;
int count = 0;
cout << "This program tells you how long it takes\n"
<< "to accumulate a debt of " << MAXDEBT
<< ", starting with\n"
<< "an initial balance of " << STARTING_DEBT
<< " owed.\n"
<< "The interest rate is " << INTRATE
<< "% per month.\n";
while (balance < MAXDEBT) {
balance = balance + INTRATE/100.0 * balance;
count++;
}
cout << "After " << count << " months, your balance\
due will be €" << balance << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment