Solved

# Two Maths functions on the same variable

Posted on 2004-11-25
198 Views

Hi,

I have a variable called var1, it's value changes throughout the program.

Towards the bottom of the program I have some maths functions which use var1.

ru = (var1 / 4) * 100;
rh = (rsg  / var1) * 100

Now the trouble I have is that I need the var1 to be the same value in both equations, but at the moment the second var1 value is the first var1 value divided by 4.

Whats the best round this?  Do I copy the var1 variable to another variable before doing the sums, if so how would this be done ?

0
Question by:andyw27

LVL 16

Accepted Solution

>>Now the trouble I have is that I need the var1 to be the same value in both equations, but at the moment the second var1 value is the first var1 value divided by 4.
If this was true then you probably either have a compiler bug or these are not sequential calculations.

If these are not sequential (you change var1 between them) then you DO indeed need to take a copy of var1 before it is changed as you suggest.

oldVar1 = var1;
ru = (var1 / 4) * 100;
...
rh = (rsg  / oldVar1) * 100

Paul
0

Author Comment

Excellent thanks very much.
0

## Featured Post

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.