//Amari Mosley CSC5 Chapter 3, P. 143, #16
//
/**************************************************************
*
* Interest Earned
* ____________________________________________________________
* This program calculates the interest earned on a savings
* account over one year.
* Computation is based on the following formula:
* Amount = Principal * (1 + Rate / T)^T
* ____________________________________________________________
* INPUT
* principal, rate, timesCompounded
* OUTPUT
* interest, amount
*
**************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// Defining Main Function
int main() {
// Define variables
double principal, rate, amount, interest;
int timesCompounded;
// Ask for the principal, interest rate, and times compounded
cout << "Enter the principal balance: ";
cin >> principal;
cout << "Enter the interest rate (as a percentage, e.g., 4.25): ";
cin >> rate;
cout << "Enter the number of times the interest is compounded during a year: ";
cin >> timesCompounded;
// Calculate the amount and interest[cite: 6]
// The rate must be converted from a percentage to a decimal for the formula
double rateDecimal = rate / 100.0;
amount = principal * pow(1 + (rateDecimal / timesCompounded), timesCompounded);
interest = amount - principal;
// Display the report formatted to match the required output[cite: 6]
cout << "\n";
cout << left << setw(20) << "Interest Rate:" << right << setw(7) << rate << "%" << endl;
cout << left << setw(20) << "Times Compounded:" << right << setw(7) << timesCompounded << endl;
// Format numeric output for currency and align the decimals[cite: 6]
cout << fixed << setprecision(2);
cout << left << setw(20) << "Principal:" << "$ " << right << setw(7) << principal << endl;
cout << left << setw(20) << "Interest:" << "$ " << right << setw(7) << interest << endl;
cout << left << setw(20) << "Amount in Savings:" << "$ " << right << setw(7) << amount << endl;
return 0;
}