Practice Problem Help!

This is a discussion on Practice Problem Help! within the C++ Programming forums, part of the General Programming Boards category; Ok, so what I have to do is get the interest rate, monthly pay, remaining balance, and interest paid for ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    3

    Practice Problem Help!

    Ok, so what I have to do is get the interest rate, monthly pay, remaining balance, and interest paid for each month for 12 months. But when I execute the code, I get the all of those things for month 1 but its the same for all 12 months (Doing a For Loop). I dont know how to even get the 4 new things for all 12 months. I spent an hour trying to figure this out LOL. (Started c++ programming a week and a half ago). Heres the code:

    Code:
    float monthly_rate = .02;
     float anual_rate = .2;
    float balance = 4800;
     float length = 12;
    
    
    for (int month = 2; month != 13; ++month)
        
    {
            cout << "Month: " << month << endl;
            
            float monthly_pay = monthly_rate * balance;
            float interest_paid = anual_rate / length * balance;
            float principal_paid = monthly_pay - interest_paid;
            float remaining_balance = balance - principal_paid;
    
    
            cout << "Monthly Payment is: " << monthly_pay << endl;
            cout << "Interest Paid is : " << interest_paid << endl;
            cout << "Principal Paid is: " << principal_paid << endl;
            cout << "Remaining Balance is: " << remaining_balance << endl;
    
    
      }
    I tried puting "new balance" and "new monthly pay" as variables and put the same equations in thinking the loop will keep storing the new numbers in them but that didnt work either. What am I doing wrong?
    Last edited by PCBeginner; 06-14-2012 at 09:19 AM.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,197
    Code:
    float monthly_pay = monthly_rate * balance;
    "monthly_rate" and "balance" are initialized before the loop, and their values never change inside of the loop, therefore the product of these two values will be the same for each loop iteration.

    Code:
    float interest_paid = anual_rate / length * balance;
    float principal_paid = monthly_pay - interest_paid;
    float remaining_balance = balance - principal_paid;
    These values also remain static for each iteration of the loop.

    Perhaps what you're looking for is to incorporate the variable that is being changed for each iteration of the loop into the equations; then values will change each time the loop cycles.

  3. #3
    Registered User R41D3N's Avatar
    Join Date
    Mar 2012
    Location
    ...Beyond Infinity, Behind a KeyBoard...
    Posts
    29
    This is where it falters at:

    Code:
    float remaining_balance = balance - principal_paid;
    try changing it to something like:

    Code:
    balance -= principal_paid;
    
    /*---*/
    cout << "Remaining Balance is: "<< balance << endl;
    So your balance gets deducted every month (remaining balance). Also put a check to see whether your balance has hit 0, so as to stop the loop.
    Last edited by R41D3N; 06-14-2012 at 10:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. an practice problem on C and OS
    By oldercoder in forum C Programming
    Replies: 4
    Last Post: 02-07-2012, 09:59 AM
  2. Problem with cprogramming practice problem #1
    By joeyj86 in forum C++ Programming
    Replies: 4
    Last Post: 01-03-2012, 10:48 PM
  3. Even or Odd (practice problem)
    By Amphibian in forum C Programming
    Replies: 16
    Last Post: 09-22-2010, 01:32 PM
  4. inStream practice problem not working?
    By correlcj in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2002, 04:58 PM
  5. Question on an array practice problem
    By Vanished in forum C Programming
    Replies: 1
    Last Post: 01-22-2002, 06:12 PM

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