I'm writing code for an interest program that will take the principal amount of the account, show the interest, show how many times it was compounded, and show the total amound in the account after all the interest is added up and also show a seperate amount for the interest accrued. This program assumes no other deposits are made into the account and the length of time of interest is 12 months.
This is the code I've come up with so far. I'm trying to break the equation amount = principal * (1 + rate / T) ^T into steps to get the total amount in the account and interest accrued. Any help on this would be appreciated as I believe this assignment is driving me slowly schizophrenic. Hopefully I've provided enough info but I'll be more then glad to fill in any missing parts. Thanks in advance.
Regards,
Matt Stacey
Code:
// CSDT 117 chp3chall12.cc
// by Matt Stacey
// 10/05/2004
// Purpose: This program will ask for an interest rate, number of
// times the interest is compounded and display a report.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
float interestRate;
float timesCompounded;
float principal;
float totalInterest;
float totalInSavings;
float compoundInterest;
cout << "Enter the principal amount in the account: " <<endl;
cin >> principal;
cout << "Enter the interest rate as a floating poing decimal: " <<endl;
cin >> interestRate;
cout << "Enter the number of times the interest was compounded: " <<endl;
cin >> timesCompounded;
cout << "Interest Rate: " <<interestRate << "%" <<endl;
cout << "Times Compounded: " <<timesCompounded <<endl;;
cout << "Principal: " << principal <<endl;
cout << setiosflags(ios::fixed) << setprecision(2);
totalInterest = interestRate / timesCompounded;
totalInterest = 1 + interestRate;
totalInterest = pow(interestRate, timesCompounded);
totalInSavings = principal * totalInterest;
cout << "The total interest accrued is $" <<totalInterest<<endl;
cout << "The total amount in savings is $"
<< totalInSavings <<endl;
return 0;
}