Adding variables to variables

L

lmo863

Hi,

I wonder if anyone can help me. I am creating a program in Borland C++
Builder. I want to do the following...

A variable, TotalTax, calculates the tax for an employee. I need to
also keep a running total for "n" employees. So i need a piece of code
to add the next value of TotalTax to the current value.

I have tried the following code;

TotalTax = TotalTax + TotalTax1 (where totaltax1 is the new value )

but it just keeps doubling the value in the original.

Does anyone know an easier way to do this, bearing in mind I have four
IF statements to determine what tax the employee has to pay!

thanks in advance
 
V

Victor Bazarov

lmo863 said:
I wonder if anyone can help me. I am creating a program in Borland C++
Builder. I want to do the following...

A variable, TotalTax, calculates the tax for an employee. I need to
also keep a running total for "n" employees. So i need a piece of code
to add the next value of TotalTax to the current value.

I have tried the following code;

TotalTax = TotalTax + TotalTax1 (where totaltax1 is the new value )

but it just keeps doubling the value in the original.

Does anyone know an easier way to do this, bearing in mind I have four
IF statements to determine what tax the employee has to pay!

The "easier" way to do what you have above is

TotalTax += TotalTax1

but it will probably not fix your doubling issue because it is reasonable
to assume that it's not due to this addition, but due to calculation of
'TotalTax1'.

Since you're the one who's in charge of making your code work, you will
have to put some more effort to it. You have what is known as "a bug" in
your code. So, you have to de-bug your program. Use a "debugger" or do
a manual trace of your program with a pencil and a piece of paper, just
do it. We cannot do it for you because we don't have your code.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top