Thread: Newbie to C++ needs help plz!!

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    4

    Newbie to C++ needs help plz!!

    Sorry for bothering yall, I just need help if you dont mind. Im new to c++ programming and I need some help. I tried using other references like some books that i have but they didnt really help.

    Title: Interest Earned

    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

    where Principal is the balance in the account, Rate is the annual interest rate, and T is the number of times the interest is compounded during a year. (e.g., 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 the following:

    Interest Rate: 4.25%
    Times Compounded: 12
    Principal: $1000.00
    Interest: $43.33
    Final Balance: $1043.33

    Here is what I have done but I cant finish because Im getting all these errors
    Im using Dev C++ for this.

    Heres what i got:

    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    
    double TimesCom = 0.0;
    double InterestRate = 0.0;
    double Principal = 0.0;
    double Interest = 0.0;
    double FinalBalance = 0.0;
    
    cout << "Enter the principal balance in the account: ";
    cin >> Principal;
    cout << "Enter the annual interest rate percentage: ";
    cin >> InterestRate;
    cout << "Enter the number of times the interest is compounded (months): ";
    cin >> TimesCom;
    
    //This is where i have trouble I tried the using the formula above  Amount(final balance) = Principal * ( 1 + Rate/T ) ^T
    
    InterestRate = InterestRate / 100;
    
    // This is where i need help I did this to see to find the final balance but it doesnt let me compile because of some problems with it
    
    FinalBalance = Principal * (1 + (InterestRate / TimesCom))^TimesCom;
    
    //I also tried using the pow to get the TimesCom to the power of the formula like so
    
    FinalBalance = Principal * pow(1 + (InterestRate / TimesCom), TimesCom);
    
    //but once i get the Final Balance I assume this is how i get the output of the interest
    
    Interest = FinalBalance - Principal;
    
    cout << "Interest Rate: " << InterestRate << endl;
    cout << "Times Compounded: "<< TimesCom << endl;
    cout << "Principal: "<< Principal << endl;
    cout << "Interest: " << Interest << endl;
    cout << "Final Balance: " << FinalBalance << endl;
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
    
    }
    
    /* 
    
    This is what the outcome should be 
    
    Interest Rate: 4.25%
    Times Compounded: 12
    Principal: $1000.00
    Interest: $43.33
    Final Balance: $1043.33
    
    */
    Thanks for looking and helping
    Last edited by xuder; 01-22-2008 at 08:10 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You posted in code tags, that's good, but the indenting is still missing making it a bit harder to read the code.

    You also didn't post the errors. It will make it easier and faster for someone to spot the error if you paste the exact error messages. At first glance, the code looks fine, including the InterestRate / 100 line.

    If you're just having trouble accomplishing the next part, post what you've tried on that (what you think is your best attempt) and it will be easier to help with specific suggestions.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Quote Originally Posted by xuder
    I cant finish because Im getting all these errors
    What errors? Are we supposed to be psychic?

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    4
    o ok sorry about that ill edit the post

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    4
    Ok post is edited

    Thanks for helping out I appreciate it!

  6. #6
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149
    Try adding:
    Code:
    #include <cmath>
    in your code, so you can use the "pow" function in this line:
    Code:
    FinalBalance = Principal * pow(1 + (InterestRate / TimesCom), TimesCom);

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    4
    Omg Thank you so much!

    it compiled fine now!

    so I was just missing the #include <cmath>

    thank you very much for the help

  8. #8
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    InterestRate = InterestRate / 100;
    Why did you divide Interest rate by 100? If the user inputs 4.65 then it will become 0.0465


    I think....but I am not sure that the ^ operator is not allowed in C++ (I may be wrong)
    You can use loops.

  9. #9
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Code:
    I think....but I am not sure that the ^ operator is not allowed in C++ (I may be wrong)
    it is allowed, but for something totally unrelated - it is the operator for exclusive OR.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Why did you divide Interest rate by 100? If the user inputs 4.65 then it will become 0.0465

    The interest rate is input as a percentage, but used in the calculations as a normal decimal ratio.

  11. #11
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    The interest rate is input as a percentage, but used in the calculations as a normal decimal ratio.
    I still don't get it. If the interest rate is 4.25&#37;, then tell me what I am supposed to put in the formula
    Code:
    Amount = Principal * ( 1 + Rate/T ) ^T
    in place of "Rate"?

    0.0425 or just 4.25 ?

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You should use 0.0425, since 4.25% is 0.0425 as a "multiplier".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie needs help plz
    By boffinson in forum C++ Programming
    Replies: 22
    Last Post: 07-29-2006, 03:25 AM
  2. Plz help this newbie
    By Desperate in forum C++ Programming
    Replies: 6
    Last Post: 07-10-2006, 10:26 PM
  3. im newbie to opengl, help plz
    By NecroFromHell in forum C++ Programming
    Replies: 4
    Last Post: 05-14-2006, 08:24 PM
  4. Plz help a coding newbie!
    By Zophixan in forum C++ Programming
    Replies: 7
    Last Post: 11-01-2002, 08:06 AM
  5. HI .. newbie to the board... need some help plz
    By Arwen27 in forum C Programming
    Replies: 3
    Last Post: 04-28-2002, 07:27 AM