//Written by Mark Lair

//September 02, 2007

//Chapter 3

//Assignment 16, interest earned

//this program will calculate interest
// on a given principal amount
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;


int main()
{
// declare constants and variables

	double amount;
	double principal;
	double interestRate;
	double interest;
	double compRate;
	double x;
	double y;

// collect information


	cout << "Enter your principal balance:" << endl;
	cin >> principal;
	cout << "Enter your interest rate in decimal form:" << endl;
	cin >> interestRate;
	cout << "How many times per year is the " << endl;
	cout << "interest compunded?" << endl;
	cin >> compRate;


//calculations

	x = 1 + (interestRate / compRate);
	y = pow (x, compRate);
	amount = principal * y;
	interest = amount - principal;

// display values

	cout << setw(20) << left << "Interest Rate: " << setw(20) << right << setprecision(2) << fixed << interestRate * 100 << "%" << endl;
	cout << setw(20) << left <<"Times Compounded: " << setw(20) << right << compRate << endl;
	cout << setw(20) << left <<"Principal: " << setw(20) << right << principal << endl;
	cout << setw(20) << left <<"Interest: " << setw(20) << right << interest << endl;
	cout << setw(20) << left <<"Amount in Savings: " << setw(20) << right << amount << endl;


	return 0;


}

