C Program ming - Calculations

This is a discussion on C Program ming - Calculations within the C Programming forums, part of the General Programming Boards category; Hi, A newbie here so go easy eh... Just wanted a bit of advice on calculations and the hierarchy inside ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    25

    C Program ming - Calculations

    Hi,

    A newbie here so go easy eh...

    Just wanted a bit of advice on calculations and the hierarchy inside a function.

    I am trying to get a program working that calculates the potential difference across a wheatstone bridge circuit.

    The formula for this is

    Vb = Vin * R2 Rx
    -------- - -------
    R2 + R1 Rx + Rs


    My code for this function is


    float potential (float R1, float R2, float Rs, float Rx)
    return( 30 * R1 / (R1 + R2) - Rx / (Rx + Rs));



    Where 30 = Vin

    But the calculation is not working, no errors just not the output that is correct.

    Any help guys?

    Thanks
    Keith

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Which of the following do you want
    Attached Images Attached Images   

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    Either of the above work, I just cannot get the formula within the function:

    return( 30 * (R1 / (R1 + R2)) - (Rx / (Rx + Rs)));

    This above in my mind should do the same but it is not, unless i am missing something very basic.

    Thanks..

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The reason I posted the two versions is that they are not the same. You need to look at your formula and decide which one matches. (For future reference, you are doing the first one.)

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    Thanks...

    Still not working even when I try the second one, will just have to plough on and do the calculation a different way rather than via a function.

    Cheers anyway..

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by boom71uk View Post
    Thanks...

    Still not working even when I try the second one, will just have to plough on and do the calculation a different way rather than via a function.

    Cheers anyway..
    Did you actually try the second one? (Since that one is, after all, the formula.)

    Note the difference between the first:

    return( 30 * (R1 / (R1 + R2)) - (Rx / (Rx + Rs)));

    and the second:

    return( 30 * (R1 / (R1 + R2) - Rx / (Rx + Rs)));

  7. #7
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    I did try the second one but think I added an extra pair of brackets, your above one works great.

    Thanks, appreciated..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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