Review: Interest Earned

Jun 13, 2011 at 4:18am
Hello, I'm having a problem running this program. The problem occurs when I have to enter the values for the code to run.

/*Assuming there are no deposits other than the original investment, the balance in a
savings account after one year may be calculated as

Amount = Principal * ( 1 + (Rate / T))^T

Principal is the balance in the savings account, Rate is the interest rate, and T is the
number of times the interest is compounded during a year (T is 4 if the interest is
compounded quarterly).
Write a program that asks for the principal, the interest rate, and the number of times
the interest is compounded. It should display a report similar to

Interest Rate: 4.25%
Times Compounded: 12
Principal: $1000.00
Interest: $ 43.34
Amount in Savings: $1043.34 */
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
double Principal, //The balance in the savings account
Rate, //The interest rate
T, //The number of times interest is compounded
//in a year
Interest,
Amount; //Amount of money in savings account

cout << setprecision(2) << fixed;
cout << "What is the principal, interest rate and number of times\n";
cout << "interest is compounded?" << endl;
cout << "Principal: $";
cin >> Principal;
cout << "Interest Rate: ";
cin >> Rate;
cout << "Number of times interest is compounded? ";
cin >> T;

Amount = Principal + pow((1 +(Rate / T)),T);

cout << "Amount in Savings: $" << Amount << endl;
system("pause");
return 0;
}

When I plug in the same values used in the comment I get a different result, so I would like to know where I went wrong. Thank you
Jun 13, 2011 at 4:24am
In your code, you are adding the Principal to the result of pow(), while the instructions say you should be multiplying.
Jun 13, 2011 at 4:31am
lol Wow, after all me going through it I didn't catch it all thank you
Jun 13, 2011 at 6:11am
Better a simple fix you just overlooked, I always say. Glad to be able to help.
Topic archived. No new replies allowed.