//Xinnuo Wang CS1A chapter 3 , P.146, #16
//
/*******************************************************************************
*
* Caculate earned interest
*-------------------------------------------------------------------------------
* This program asks for the principal, the interest rate, and the number of
* timesthe interest is compounded. And caculate the amount of earned interest.
*
* computation is based on the formula:
* Amount = Principal x (1 +Rate/T)^T
* Interest = Amount - Principal
*-------------------------------------------------------------------------------
* INPUT
* principal : Balance in the savings account
* rate : The interest rate in percent
* times : The number of times the interest is compounded during a year
* OUTPUT
* interst : The amount of earned interst
* amount : The amount in savings
*
*******************************************************************************/
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double principal; //INPUT - Balance in the savings account
double rate; //INPUT - The interest rate in percent
int times; //INPUT - The number of times the interest is compounded during a year
double interest; //OUTPUT - The amount of earned interst
double amount; //OUTPUT - The amount in savings
//
//Input data
cout << "Enter balance in the savings account" << endl;
cin >> principal;
cout << "Enter the interest rate" << endl;
cin >> rate;
cout << "Enter the number of times the interest is compounded during a year" << endl;
cin >> times;
//
//Compute the amount
amount = principal * pow(1+rate/100/times,times);
//
//Compute the earned interest
interest = amount - principal;
//
//Output Result
cout <<"Interest Rate: "<<fixed<<setprecision(2)<<setw(10)<<rate<<"%"<<endl;
cout <<"Times Compounded: "<<setw(6)<<times<<endl;
cout <<"Principal: $"<<fixed<<setprecision(2)<<setw(10)<<principal<<endl;
cout <<"Interest: $"<<fixed<<setprecision(2)<<setw(10)<<interest<<endl;
cout <<"Amount in Savings: $"<<fixed<<setprecision(2)<<setw(10)<<amount<<endl;
return 0;
}