Thread: Programming project help?

  1. #16
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    im just having so much confusion trying to figure out the right math to compute the interest. I know Im trying to calculate interest of each month...but the math statements throw me off. all i fized was the for loop. Other than that....im confused as to how i do the math calculations

    this is what i fixed:

    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 = 0; 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;
    }

  2. #17
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    I fixed the first correction you told me to do...but im completely lost as to how i write the math statements in order to compute the interest for each month. How do i do that?

  3. #18
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    There are formulas for compounding interest that one could use that do not require a for loop in order to work properly...

    I am not even going to torment my poor compiler with code that already looks uncompileable.

  4. #19
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Being no economist I had to look up the formula for non-continuous interest... so let me put some code, Debbie. And see if mine helps you at any capacity.

    Example:
    Code:
    #include <cmath>
    
    /*
     * A = P(1 + (r/n))^nt
     */
    double compoundInterest(double principal, double rate,
      double rate, double numberOfCompounds, double time)
    {
      return principal * pow(1.0 + (rate / numberOfCompounds), time * numberOfCompounds);
    }
    
    /*
     * A = Pe^rt
     */
    double continuousCompoundInterest(double principal, double rate, double time)
    {
      return principal * pow(M_E, rate * time);
    }

  5. #20
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    Do I need to write my math statements in a series inside the for loop? Or would I use 1 statement like...interest = (init_Balance * pow (( 1 + rate/100 , months ))) - init_Balance;

    I have no clue what to do? Can anyone help me? This is so frustrating?

  6. #21
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    disregard my last post.

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Just a tip: but when you post your code, always make sure it's indented. This should not be a problem, since your original code should also be indented properly.
    Otherwise it becomes an unreadable 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.

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