Thread: Programming project help?

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    13

    Programming project help?

    Hello, I am really confused as to how to start my project that I was given for my C++ course.

    The instructions are:

    Write a function declaration for a function that computes interest on a credit card account balance. The function takes arguments for the initial balance, the monthly interest rate, and the number of months for which interest must be paid. The value returned is the interest due. Do not forgetto compound the interest- that is, to charge interest on the interest due. This interest due is added into the balance due, and the interest for the next month is computed using this larger balance. Use a while loop. Embed the function in a program that reads the values for the interest rate, initial account balance, and number of months, then outputs ths interest due. Embed your function definition in a program that lets thge user compute the interest due on the credit account balance. The program should allow the user to repeat the calculation until the user said he or she wants to end the program.

    The information that I am given through my instructor is:

    Read the description carefully, insure that you allow the user a choice to run the program or exit.

    The function prototype is:

    double interest (double initBalance, double rate, int months);

    Your initial output to the user should be something like this:



    Credit card interest
    Enter: initial balance, monthly interest rate as
    a decimal fraction, e.g. for 1.5% per month write 0.015
    and the number of months the bill has run.
    I will give you the interest that has accumulated.
    100 .1 2

    Interest accumulated = $21.00
    Y or y repeats, any other character quits
    y

    Credit card interest
    Enter: initial balance, monthly interest rate as
    a decimal fraction, e.g. for 1.5% per month write 0.015
    and months the bill has run.
    I will give you the interest that has accumulated.
    100 .1 3

    Interest accumulated = $33.10
    Y or y repeats, any other character quits
    n

    Therefore, I am confused as to how to start with the function prototype that he gave me to start with...

    double interest (double initBalance, double rate, int months);




    Is there a possibility that anyone can lead me in the right direction to start with?

    Thank you very much,

    Debbie Bremer

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The prototype looks good. Surely you can program a function that compounds interest.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    I dont know how to type in the code for coompound interest. Basically right now, I have the program to display the instructions...but as far as the math goes for interest...im confused. Can anyone help?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Google for "compound interest calculation", perhaps?

    --
    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.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    How would you calculate it by hand? Write it out in non-code, then put it in code.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Example:
    Code:
    #include <cmath>
    
    double interest (double initBalance, double rate, int months)
    {
      return initBalance * pow(M_E, rate*months);
    }
    This will do continuously compounded interest... but I am no economics expert so its the formula I know better. Of course this is a start, and just a mere example since this is NOT the formula you were asked to use.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    For some reason I cannot get my math to work.

    This is what I have so far:

    Code:
    #include <iostream>
    using namespace std;
    int main ( )
    {
    int months, count = 1;
    double init_Balance, rate, interest = 0, new_balance, total_Interest = 0, int_Accumulated;
    char repeats;
    
    
    do
    {
    total_Interest = 0;
    {
    cout << " Credit card interest\n ";
    cout << "Enter: Initial balance, monthly interest rate as a decimal fraction, e.g. for 1.5&#37; per month write 0.015, and the number of months the bill has run.\n ";
    cout << "I will give you the interest that has accumulated.\n ";
    
    cin >> init_Balance, rate, months;
    }
    for ( int count; count <= months; count++)
    {
    
    
    interest = ( rate * init_Balance );
    
    new_balance = ( init_Balance + interest );
    
    total_Interest = ( interest + );
    cout << count ++;
    
    
    }
    
    
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    
    cout << "Interest accumulated = $\n";
    cin >> int_Accumulated;
    
    cout << "Y or y repeats, any other character quits. ";
    
    }while ( repeats != 'Y' && repeats != 'y' );
    
    
    
    return 0;
    }

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Please indent your code. You cannot possible ask us to read your unreadable code mess.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    ok sorry about that.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Well? Edit your original post and indent.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    Code:
     
    
    
    
    #include <iostream>
      using namespace std;
        int main ( )
       {
          int months, count = 1;
          double init_Balance, rate, interest = 0, new_balance, total_Interest = 0, int_Accumulated;
          char repeats;
       
       
          do
          {
             total_Interest = 0;
             {
                cout << " Credit card interest\n ";
                cout << "Enter: Initial balance, monthly interest rate as a decimal fraction, e.g. for 1.5&#37; per month write 0.015, and the number of months the bill has run.\n ";
                cout << "I will give you the interest that has accumulated.\n ";
             
                cin >> init_Balance >> rate >> months;
             }
             for ( int count; count <= months; count++)
             {
             
             
                interest = ( rate * init_Balance );
             
                new_balance = ( init_Balance + interest );
             
                total_Interest = ( interest +  );
                cout << count ++;
             
             
             }
          
          
             cout.setf(ios::fixed);
             cout.setf(ios::showpoint);
             cout.precision(2);
             {
                cout << "Interest accumulated = $\n";
                cin >> int_Accumulated;
             
                cout << "Y or y repeats, any other character quits. ";
             }
          }while ( repeats != 'Y' && repeats != 'y' );
       
       
       
          return 0;
       }

  12. #12
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    The code I just posted will not compute my math in the program. can anyone help me fix my problem?

  13. #13
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You don't initialize count in the for-loop, which means it has a pretty much random initial value - very likely more than months, so the loop never runs.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  14. #14
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    im a little confused by what you mean. does that mean i usea different variable there?

    also, im not even sure if my math equations are right?

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Code:
    for ( int count; count <= months; count++)
    Should be:
    Code:
    for ( int count = 0; count <= months; count++)
    Also, if you want to execute the loop once for every month, you need to compare with <, not <=.

    Code:
    total_Interest = ( interest +  );
    This line is meaningless and syntactically incorrect.

    Code:
    new_balance = ( init_Balance + interest );
    You overwrite new_balance every iteration without ever doing anything to the value.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM