# Thread: C Program ming - Calculations

1. ## 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. Which of the following do you want

3. 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. 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. 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. Originally Posted by boom71uk
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. I did try the second one but think I added an extra pair of brackets, your above one works great.

Thanks, appreciated..