Thread: C++ Program

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    Question C++ Program

    Can some one tell mw what I am doing wrong with this program?

    // C++ Program
    // IRA Account
    // Author:
    // Email Address: [email protected]
    // Date: FEB-23-2003


    /* This program will compute compound interest for a IRA
    with an initial investment of whatever amount in dollar and yielding
    at what ever percent interest.Assuming that all interest is left
    on deposit in the account from the age 16 to 60 years, and at age 61
    you start taking out the monthly interest to live on. You leave the
    Accumalated balances alone. How much interestincome would the person
    have to live on for each month. */


    #include <iostream>
    using std::cout;
    using std::endl;
    using std::cin;
    #include <string>
    #include <cctype>
    #include <iomanip>
    using std::setiosflags;
    using std::setprecision;
    using std::ios;
    using std::fixed;
    using std::showpoint;
    #include <cmath>


    using namespace std;






    int main () {


    double balanceAmount;
    double initialAmount;
    double interestRate;
    char response;

    double monthlyInterest;
    // int year;




    do {


    cout << "Hello! This program wil be used to calculate your IRA: \n";
    cout << "Please enter the Investment in dollars at age 16: \n";
    cin >> initialAmount;
    cout << endl;

    cout << " Please enter Interest Rate:\n";
    cin >> interestRate;
    cout << endl;

    cout << "Total accumulated at age 60 \n";
    cout << "Total accumulated at age 61 \n";
    cout << "This is monthly income from interest \n";




    for (int year = 1; year <= 50; year++ )

    balanceAmount = initialAmount* interestRate;

    monthlyInterest = balanceAmount* interestRate * (1 + interestRate)/12;






    // cout << setprecision(2) << setiosflags(ios::fixed |
    // ios::showpoint) <<balanceAmount << endl;


    cout << "would you like to run the program again? (Y/N)/";
    cin >> response;
    system("cls");
    }
    while (response=='Y'||response=='y');

    cout << "Goodbye. Have a nice day!\n";

    char letter;
    cin >>letter;

    return 0;

    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Can some one tell mw what I am doing wrong with this program?
    It might help if you mentioned what problems you are having.

    -Prelude
    My best code is written with the delete key.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    ... and even better if you used code tags. Well, maybe not *even better*, but darn good start at least
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    using std::cin;
    #include <string>
    #include <cctype>
    #include <iomanip>
    using std::setiosflags;
    using std::setprecision;
    using std::ios;
    using std::fixed;
    using std::showpoint;
    #include <cmath>
    
    
    using namespace std;
    Whats with all the std::'s?? Aren't these assumed once u declare that you are using namespace std?? Maybe im wrong but i dont think u need all that.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640

    Re: C++ Program

    Originally posted by bigger

    for (int year = 1; year <= 50; year++ )

    balanceAmount = initialAmount* interestRate;

    monthlyInterest = balanceAmount* interestRate * (1 + interestRate)/12;
    What are you trying to do here? You're not even using the for
    loop?
    --

  6. #6
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    i think he means those two lines for the loop and didnt {} them like you should.

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by RoD
    i think he means those two lines for the loop and didnt {} them like you should.
    Even if he forgot them, He isn't using the variable year, So what's
    the use of the FOR loop?
    --

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    5
    Originally posted by RoD
    i think he means those two lines for the loop and didnt {} them like you should.

  9. #9
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    Question Re: Re: C++ Program

    Originally posted by Travis Dane
    What are you trying to do here? You're not even using the for
    loop?
    [QUOTE]Originally posted by bigger
    [Travis] What i was trying to do was: Make a for loop that would go through the years starting from the person 16th brithday and add the blance amount plus the compounding interest amount for each year up to the person 60th brithday and come up with how much money the person would have in his account at 60. Then if he just used the insterest amount that the account had accumulated in the 44 years, how much money a month would the person have to live on for the rest of his life. I can not use the pow() in the program at all.
    I am just starting to learn C++ so I know just enough to be dangers. I would be thankful for any help. I know the loop don't work but i don't know why. [/Travis][/OUOTE]

  10. #10
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    Post

    Originally posted by Prelude
    >Can some one tell mw what I am doing wrong with this program?
    It might help if you mentioned what problems you are having.

    -Prelude
    [OUOTE][i]Originally posted by bigger[i]
    [Prlude]>Thanks for the advise new at posting just tring to learn.
    the problem is that once i enter the initial amount and interest rate in, the program skips over the for loop and goes to the end.
    It will not do the compounding of interest or balance amount for the 44 years. That is from 16 to 60. It will not give me the monthly
    interest amount total, for the years.

    Thanks for interest in helping me!
    -bigger [Prelude][/OUOTE]

    -bigger

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    your problem is the for loop. you need braces.

    Code:
    for (int year = 1; year <= 50; year++) {
    			balanceAmount = initialAmount* interestRate;
    			monthlyInterest = balanceAmount* interestRate * (1 + interestRate)/12;
    		}
    also uncomment the lines to output the balanceAmount. If this doesn't solve it, post up.

  12. #12
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    Question C++ program

    [Ouote][i]Originally posted by bigger[i]

    [Prelude]> i apply the braces and that did nothing to solve the problem, the program still acts the when i run the program it comes up i enter the amount ie. 1000.00 and i enter the interest rate ie. 10, and the program goes to the end and ask if i wnat to enter another.

    Could i have my cout; for the for the total accumulated at age 60, total accumulated at age 61 and my Monthly income from interest in the wrong place. do you think the way i have coded the for loop is correct to produce these outputs, or should i have a total for accumulated and yearly interest.

    Thanks again for your help, will most likely be here all night trying to solve this.

    -bigger [Prelude] [/OUTE]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM