//Zachary Abdollahi CS1A Chapter 3, P. 146, #16
//
/*******************************************************************************
*
* COMPUTE INTEREST EARNED
* ____________________________________________________________________________
*
* This program calculates the balance in a savings account after one year,
* assuming there are no deposits other than the original investment.
*
* Computation is based on the formula:
* Amount = Principal x (1 + Rate / T) ^ T
* _____________________________________________________________________________
*
* INPUT
* principal : Balance in the savings account
* rate : Interest rate
* timesCompounded : Number of times interest is compounded during the year
*
* OUTPUT
* interest : Interest earned over the year
* amount : Amount in savings after one year
*
******************************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main ()
{
float principal; //INPUT - Balance in the savings account
float rate; //INPUT - Interest rate
int timesCompounded; //INPUT - Number of times interest is compounded
float interest; //OUTPUT - Interest earned over the year
float amount; //OUTPUT - Amount in savings after one year
//
// Get Input From User
cout << "Enter the principal: ";
cin >> principal;
cout << "Enter the interest rate (as a percentage): ";
cin >> rate;
cout << "Enter the number of times the interest rate is compounded: ";
cin >> timesCompounded;
//
// Compute Amount in Savings and Interest Earned
amount = principal * pow((1 + (rate / 100) / timesCompounded), timesCompounded);
interest = amount - principal;
//
// Output Result
cout << fixed << setprecision(2);
cout << endl;
cout << "Interest Rate: " << setprecision(2) << rate << "%" << endl;
cout << "Times Compounded: " << timesCompounded << endl;
cout << "Principal: $ " << setw(7) << principal << endl;
cout << "Interest: $ " << setw(7) << interest << endl;
cout << "Amount in Savings: $ " << setw(7) << amount << endl;
return 0;
}