Discussion in 'C++' started by lmo863, Aug 3, 2005.

1. ### lmo863Guest

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!

lmo863, Aug 3, 2005

2. ### Victor BazarovGuest

lmo863 wrote:
> 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

Victor Bazarov, Aug 3, 2005