Thread: compounding interest

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    2

    compounding interest

    Code below was supposed to display interest yearly. i.e:
    Year 1 $1000
    Year 2 $1100
    Year 3 $1210
    etc

    However, it's not doing that. It's listing the end year result in every year. What am I missing? My professor is inept and can't explain it to me. Any help would be greatly appreciated.

    //compound interest
    #include<iostream.h>
    #include<iomanip.h>
    #include<math.h>
    main()
    {
    int n;
    float principle,rate,amount;
    cout<<"This will determine the compound interest over the entered number "
    <<"of years";
    cout<<"Enter the principal: $";
    cin>>principle;
    while (principle !=-1){
    cout<<"Enter rate in decimals: ";
    cin>>rate;
    cout<<"Enter number of years: ";
    cin>>n;
    for(int year=1;year<=n;year++){
    amount=principle*pow(1+rate,n);
    cout<<"Year "<<year<<setw(12)<<setiosflags(ios::fixed)
    <<setiosflags(ios::showpoint)
    <<setprecision(2)<<"$"<<amount<<endl;
    }
    cout<<"Enter principle or -1 to end: ";
    cin>>principle;
    }
    return 0;

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    amount=principle*pow(1+rate,n);

    in this n is a constant and 1+rate is a constant so no matter how many times thru the loop the end result is always the same. do you mean something like this :-

    amount=principle*pow(1+rate,year);
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    2

    Smile wow... many thanx!

    You are the man!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-11-2009, 12:54 PM
  2. Programming project help?
    By Debbie Bremer in forum C++ Programming
    Replies: 21
    Last Post: 10-11-2008, 02:48 AM
  3. creating and using functions
    By moy18 in forum C Programming
    Replies: 2
    Last Post: 10-31-2007, 09:09 PM
  4. Compound Interest Formula
    By veronicak5678 in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2007, 05:16 PM
  5. compound interest
    By bliznags in forum C Programming
    Replies: 11
    Last Post: 03-20-2005, 01:46 AM