1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Awk Help

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

Thread Status:
Not open for further replies.
  1. Scarface23

    Scarface23 Thread Starter

    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

    AGCurry

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

    Where's your "if"?

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

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/544185

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice