# Problem with equation in my algorithm

• 07-17-2007, 05:00 PM
romina
Problem with equation in my algorithm
Here is the entire code everything compiles ok, but when I run the application, the total I'm looking for comes out as a negative, I need it to come out as a positive. The equation given to compute the state tax is 0.03 x (Income - (600 x # of dependents).

Code:

```import java.io.*; public class StateTax { public static void main(String[] args) throws IOException { //declares and constructs variables String income, dependents; int amt, amt2; double stateTax; BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in)); //print prompts and get input System.out.println("\tSTATE TAX COMPUTATION"); System.out.println(); System.out.print("\t\tEnter Taxpayer's Income: "); income = dataIn.readLine(); amt = Integer.parseInt(income); System.out.println(); System.out.print("\t\tEnter Number of Dependents: "); dependents = dataIn.readLine(); amt2 = Integer.parseInt(dependents); System.out.println(); //calculations stateTax = .03 * ((double)amt - (600 * amt2)); //output System.out.println(); System.out.println("\tSTATE TAX DUE IS " + stateTax + "."); System.out.println(); } }```
Thanks
• 07-20-2007, 07:34 AM
cruxblack
I don't see anything wrong in the code, maybe it's the input ur entering for this calculation that's too small
Code:

```//calculations stateTax = .03 * ((double)amt - (600 * amt2));```
The equation will surely give a negative value if the income are too small right
I tried putting the minimum value of 600 for a dependant of 1,and it runs just ok :D
If u don't want it to go negative, just put an if clause to prevent it :)
• 07-20-2007, 07:53 AM
shameel
what cruxblack said is write, nothing wrong with ur code.based on ur formula,
if u give the value of amt greater than 600 and give the value of amt2 1 then only u will get positive value[amt=601,amt2=1 will be small positive value in this formula].according to this way u have to give values, otherwise give some restrictions in the time of values input, like amt would be > 600, like something.