Thread: beginner question / formula

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    28

    beginner question / formula

    http://img529.imageshack.us/img529/9808/helpz.png

    pretty new to c programming (in a class) so i've been running through the chapters to figure this one but but not really sure.

    would this be float, a, p, i, n, mortgage;?

    and mortgage = the formula?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What do you need to know exactly?
    It looks like you've been given an assignment of creating a program that calculates something and prints out the result. So you need to create variables, do the calculation and print the result.
    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.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I would use floats ONLY when, for some reason, you can't use doubles for your floating point data type.

    Yes, a = monthly payment, just like the picture shows.

    work inside the parentheses first, with multiplication and division having priority over addition and subtraction.

    Then repeat that, after you have simplified the inner, parenthesized sets.

    Since this is basic math, I doubt you'll find much in your programming book, to help you.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    That diagram is misleading. The author meant to say

    (1+i/12) to-the-exponent (-12n)

  5. #5
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    I would look at arithmetic operators and math.h functions.

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    int main ()
    {
    double a, p, i, n, total;

    printf ("Enter monthly mortgage payment \n");
    scanf ("%f", &a);
    printf ("loan amount? \n");
    scanf ("%f", &p);
    printf ("annual interest rate? \n");
    scanf ("%f", &i);
    printf ("how many years? \n");
    scanf ("%f", &n);
    is what i have now
    should i split up these calculations x= p(i/12)/(1-(1+i/12)(-12n)? and then the answer to that cout<<pow(x,12)<<endl;
    and the answer to that times n?

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Are you using C or C++?
    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.

  8. #8
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    regular c, sorry did not mean to have the int main there

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    cout is C++. So is endl.
    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.

  10. #10
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    Quote Originally Posted by Elysia View Post
    cout is C++. So is endl.
    oh okay. guess this tutorial is no good then.

  11. #11
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    so is it just pow(-12) ?

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    pow takes two arguments: the base and the exponential.
    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.

  13. #13
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    i guess my question is is how do i put this into c?
    do i split up this long formula into parts such as first do the beginning... then take that and put it to the power of -12.. then take that and times it by n? or would i just put the whole thing in at once such as
    x= p(i/12)/(1-(1+i/12)*pow(-12)*n.
    just need some direction that i know im doing something right before i spend hours doing trial and error. (man i wish we started with something easier)

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You can do both. You can treat C as a mathematical language.
    + - * and / work just as in math. So you can write that formula directly. Exponentials are handled by pow.
    Variables must be created in C. So you define them first. Then you can assign them values and use those values in your calculation.
    The expression

    x= p(i/12)/(1-(1+i/12)*pow(-12)*n

    is perfectly fine if you've defined x, p and i (and filled them with appropriate values).
    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.

  15. #15
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    thank you for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. Beginner: Linked List question
    By WeatherMan in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2008, 07:16 AM
  3. Quick IF statement question (beginner)
    By jim.rattlehead in forum C Programming
    Replies: 23
    Last Post: 11-29-2007, 06:51 AM
  4. a beginner question
    By xpflyer2002 in forum C Programming
    Replies: 6
    Last Post: 03-07-2004, 05:24 PM
  5. Beginner on Win32 apps, lame question.
    By Templario in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 08:39 PM