# Awk Help

Discussion in 'Software Development' started by Scarface23, Feb 14, 2007.

Not open for further replies.

Joined:
Aug 4, 2004
Messages:
45
I have an assignment to write a program in awk, its takes a file and figures gross pay, state taxes, federal taxes, total taxes, and net pay.

My problem is w/ the state taxes part, this is my first awk program and I thinnk the problem is with the variable. I get an error at the line "stateTaxVar = \$3>0 && \$3<6 { stateTaxVar = GrossPay*(10-5)/100}"

Anyway here is the problem and my program so far.

For state taxes the default withholding rate is 10%.
If the number of allowances is 0 then deduct 0% from the default rate.
If the number of allowances is between 1 and 5 then deduct 5% from the default rate.
If the number of allowances is between 6 and 9 then deduct 7.5% from the default rate.
If the number of allowances is 10 then deduct 10% from the default rate.

BEGIN{
hours = 0
gross = 0
tax = 0
stateTaxVar = 0
GrossPay = 0
print "NAME Gross Pay State Tax Fed Tax Total Tax Net Pay\n"
}

{
GrossPay = \$6*\$4+\$5*\$6*1.50
stateTaxVar = \$3>0 && \$3<6 { stateTaxVar = GrossPay*(10-5)/100},
\$3>6 && \$3<9 { stateTaxVar = GrossPay*(10-2.50)/100}, \$3 == 10 {
stateTaxVar = GrossPay*10/100}
}
{
printf"%-10s \t%d \t%d \t%.2f \t%d \t%.2f\t%.2f \n", \$1, GrossPay, stateTaxVar, \$4,
\$5, \$2*\$3, \$2*\$3*0.25 }

{
hours += \$3
gross += (\$2 * \$3)
tax += (\$2 * \$3) * 0.25
}

END{
printf"\n TOTALS: \t\t%d \t%.2f\t%.2f \n", hours, gross, tax
}

2. ### AGCurry

Joined:
Jun 15, 2005
Messages:
431
Well...

if ( \$3 > 0 && \$3 < 6 )
{ stateTaxVar = GrossPay * ( 10 - 5 ) / 100 } ;
else
...

As Seen On