Interest program

This is a discussion on Interest program within the C++ Programming forums, part of the General Programming Boards category; Can someone please help me? Okay if a principal amount is P, for which the interest is compounded Q times ...

  1. #1
    Unregistered
    Guest

    Interest program

    Can someone please help me? Okay if a principal amount is P, for which the interest is compounded Q times per year, is placed in a savings account, then the amount of money in the account (the balance) after N years is given by the following formula where I is the annual interest rate as a floating-point number:

    balance = P x (1 + I/Q) to the (N x Q) power. I have to write a program that inputs the values for P, I, Q, and N and outputs the balance for each year up through year N that uses a value-returning function to compute the balance and also prompts the user. Here is my code so far. Can someone tell me if I'm taking the right route or what else I need to do.

    // Algorithm
    // (1) Get input value for principal amount
    // (2) Get annual interest rate
    // (3) Get amount of times per year interest rate is compounded
    // (4) Get amount of years interest is to be compunded
    // (5) Use a value returning function to compute the balance
    // (6) Output values

    #include <iostream>
    #include <iomanip>

    float P, I, Q, N;

    int main()
    {
    cout.setf(ios::fixed,ios::floatfield);
    cout.setf(ios::showpoint);
    cout<<setprecision(2);

    cout<<"Enter principal amount"<<endl;
    cin>>P;
    cout<<"Enter annual interest amount"<<endl;
    cin>>I;
    cout<<"Enter amount of times interest is compunded per year"<<endl;
    cin>>Q;
    cout<<"Enter amount of years interest is to be compunded"<<endl;
    cin>>N;

    return P * (1 + (I / Q)^(N * Q);
    }

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Here is a tip, if you aren't absolutely sure it's in the langauge, don't use it. I had this problem before, and it made me really dislike programming. I had some experience with BASIC, and figured everything in BASIC should be in C++ as well. It will just add a lot of frustration. You need the pow in the <cmath> header to do this. In C++, this P * (1 + (I / Q)^(N * Q) looks like, also note that you were missing a closing paren.

    P * ( 1 + pow(I/Q, N*Q));
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Unregistered
    Guest
    Would this code work for what I wanted the program to do?

    // Algorithm
    // (1) Get input value for principal amount
    // (2) Get annual interest rate
    // (3) Get amount of times per year interest rate is compounded
    // (4) Get amount of years interest is to be compounded
    // (5) Use a value returning function to compute the balance
    // (6) Output balance value

    #include <iostream>
    #include <iomanip>
    #include <cmath>

    float P, I, Q, N;

    int main()
    {
    cout.setf(ios::fixed,ios::floatfield);
    cout.setf(ios::showpoint);
    cout<<setprecision(2);

    cout<<"Enter principal amount"<<endl;
    cin>>P;
    cout<<"Enter annual interest amount"<<endl;
    cin>>I;
    cout<<"Enter amount of times interest is compunded per year"<<endl;
    cin>>Q;
    cout<<"Enter amount of years interest is to be compunded"<<endl;
    cin>>N;

    return P * (1 + pow(I/Q),N*Q));
    }

  4. #4
    Unregistered
    Guest
    I don't think you want to return the answer, return is there to tell the os if the program ran succesfully or not. Just use cout to show the answer instead.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compound Interest Formula
    By veronicak5678 in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2007, 06:16 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 11:58 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21