[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Two Maths functions on the same variable


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 ?

Thanks in advance.
0
andyw27
Asked:
andyw27
1 Solution
 
PaulCaswellCommented:
>>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
 
andyw27Author Commented:

Excellent thanks very much.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now