Making interest rate program in C

This is a discussion on Making interest rate program in C within the C Programming forums, part of the General Programming Boards category; In my effort to become a software developer, I am faced with the project (more likely than not simple to ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    1

    Exclamation Making interest rate program in C

    In my effort to become a software developer, I am faced with the project (more likely than not simple to the experience) where I must determine the monthly payment of a loan
    Obviously to determine the monthly payment, the equation is :

    rate*(1+rate)^n
    ----------------------------------*L
    ((1+rate)^n-1)

    rate = the monthly interest
    n = # of payments
    l = loan amount

    I am stumped as how to include the exponent into the code. obviously cmath is to be used:

    let me give you what i have done, it is actually not much, as none of the MATH has actually been done:
    Code:
    #include <cmath>
    #include <cstdio>
    #include <iostream>
    
    using namespace std;
    
    int main () 
    {
    int loan; // Loan amount taken out
    int payments; // Number of payments as well as exponent
    int interest; // monthly interest rate 
    int result; // monthly payment
    bool notValid;
    
    
    cout <<"Use this program to";
    cout <<"determine monthly interest - enter loan amount\n";
    do {
    notValid =false;
    cin>>loan;
    
    if (loan < 10 || loan> 999999)
    {
    cout <<"\n The loan amount must";
    cout <<"be between $10 and $999,999.99"; 
    notValid=true;
    }
    }while (notValid);
    
    cout <<"\n Enter number of monthly payments:";
    do {
    notValid =false; 
    cin>>payments;
    
    
    if (payments < 10 || payments> 360)
    {
    cout <<"\n The monthly payments must";
    cout <<"be between 12 and 360 months"; 
    notValid=true;
    }
    }while (notValid); 
    }
    -----------
    All i have included are two of the inital equations ( I still have to ask how much the interest is, which isnt a problem) and the validation problem aka making sure the user inputs are between the specificed range.

    Im not asking for this to be written for me, obviously I have to do that - which I want to - i want to learn the process of how this is done, and maybe if there is a more efficent way to doing this. Also note that this is a structed programming intro course to C, so for any explanations - please try to keep it in those terms.

    I also have to present this information back to the user, but Im pretty sure how to do that. Any help would be great


    thanks in advance
    you can respond here or my aim is chikkennn

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I am stumped as how to include the exponent into the code. obviously cmath is to be used:
    In C:
    Code:
    #include <math.h>
    int x = pow(2, 8);  /* 2 to the power of 8 = 256 */
    In C++:
    Code:
    #include <cmath>
    int x = pow(2, 8);  /* 2 to the power of 8 = 256 */
    dwk

  4. #4
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    I believe in C++ it would have to be "pow((double)2, 8)" or "pow(2.0, 8)" to keep the compiler happy.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Sorry, I was so concerned about the header file that I missed that . . . .

  6. #6
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    A quick google indicates that both variables are supposed to be doubles: http://www.hmug.org/man/3/pow.php

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    36
    But on the other hand, with simple algebra, your problem simplifies to rate * (1+rate), so why bother?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't stop my program at zero (Loan Table)
    By beachsidefl321 in forum C Programming
    Replies: 10
    Last Post: 06-24-2009, 09:14 PM
  2. Making A Simple Program
    By switch-blade in forum C++ Programming
    Replies: 25
    Last Post: 09-12-2008, 07:44 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  4. making my program sleep / wait / delay...
    By bobthebullet990 in forum C++ Programming
    Replies: 4
    Last Post: 08-13-2006, 10:14 AM
  5. making a program leave a msg for background program when it closes
    By superflygizmo in forum Windows Programming
    Replies: 2
    Last Post: 02-06-2006, 06:44 PM

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