Adding variables to variables

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

  1. lmo863

    lmo863 Guest

    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
     
    lmo863, Aug 3, 2005
    #1
    1. Advertising

  2. 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
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cybermedia Marketing

    Adding custom server variables from http module

    Cybermedia Marketing, Oct 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    512
    Cybermedia Marketing
    Oct 15, 2003
  2. Scott Balmos
    Replies:
    1
    Views:
    648
    Steve W. Jackson
    Aug 31, 2005
  3. iwl
    Replies:
    3
    Views:
    660
  4. Elmo Watson

    Adding DotNet Variables to Javascript URL

    Elmo Watson, Dec 18, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    364
    Cowboy \(Gregory A. Beamer\)
    Dec 18, 2007
  5. Replies:
    9
    Views:
    961
Loading...

Share This Page