• C

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.
andyw27Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andyw27Author Commented:

Excellent thanks very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.