# Thread: Problem with equation in my algorithm

1. Member Join Date
Jul 2007
Posts
26
Rep Power
0

## 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).

Java 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;

//print prompts and get input
System.out.println("\tSTATE TAX COMPUTATION");
System.out.println();
System.out.print("\t\tEnter Taxpayer's Income: ");
amt = Integer.parseInt(income);
System.out.println();
System.out.print("\t\tEnter Number of Dependents: ");
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  Reply With Quote

2. Senior Member Join Date
Jul 2007
Posts
130
Rep Power
0

## I don't see anything wrong in the code, maybe it's the input ur entering for this calculation that's too small
Java 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 :)  Reply With Quote

3. Member Join Date
Jul 2007
Posts
9
Rep Power
0

## 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.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•