View Single Post
Old 10-07-2004, 02:28 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Next time use the "CODE" tags .

Does this come closer to what you want?
Code:
// Purpose: This program will ask for an interest rate, number of
// times the interest is compounded and display a report.

//amount = principal * (1 + rate / T) ^T

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
  double interestRate, timesCompounded, principal, totalInterest, totalInSavings,
      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: " <<100*interestRate << "%" <<endl;
  cout << "Times Compounded: " <<timesCompounded <<endl;;
  cout << "Principal: " << principal <<endl<<endl;;

  cout << setiosflags(ios::fixed) << setprecision(2);

   totalInterest = 1 + (interestRate / timesCompounded);
  compoundInterest = pow(totalInterest, timesCompounded);
  totalInSavings = principal * compoundInterest;

  cout << "The total interest accrued is $" <<totalInterest<<endl;
  cout << "The compound interest is $" <<compoundInterest<<endl;
  cout << "The total amount in savings is $"<< totalInSavings <<endl;
  //Optional line below:
  system("PAUSE");

  return 0;
}
By the way, standard C++ proposes "double" as the standard precision. Forget float.
__________________
Valmont is offline   Reply With Quote