Thread: garbage values

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    garbage values

    Hey all,

    I'm trying to write a program that will calculate an employees pay when given the hours worked and the pay rate. I get garbage values for Gross, stateTax, federalTax, FICA, and NetPay.

    Code:
    void getData (int* emplNum, int* hoursWorked, int* rate);
    int calculateGross (int hoursWorked, int rate, int* Gross);
    int calcTaxes (int Gross, int* stateTax, int* federalTax);
    int calcFICA (int Gross, int* FICA);
    int calcNetPay ( int Gross, int stateTax, int federalTax, int FICA, int* NetPay);    //after tax pay
    void print_them (int emplNum, int Gross, int stateTax, int federalTax, int FICA, int NetPay);
    
    #include <stdio.h>
    int main (void)
    {
    int emplNum, hoursWorked, rate, Gross, Taxes, NetPay, stateTax, federalTax, FICA;
    getData (&emplNum, &hoursWorked, &rate);
    Gross = calculateGross (hoursWorked, rate, &Gross);
    Taxes = calcTaxes (Gross, &stateTax, &federalTax);
    FICA = calcFICA (Gross, &FICA);
    NetPay = calcNetPay (Gross, stateTax, federalTax, FICA, &NetPay);
    print_them (emplNum, Gross, stateTax, federalTax, FICA, NetPay);
    return 0;
    }
    
    
    
    void getData (int* emplNum, int* hoursWorked, int* rate)
    {
    printf ("Enter your Employee Number, how many hours you worked (round to the nearest hour), and your pay rate");
    scanf ("%d%d%d", emplNum, hoursWorked, rate);
    return;
    }
    
    
    
    int calculateGross (int hoursWorked, int rate, int* Gross)
    {
    if (hoursWorked <= 40)
       *Gross = hoursWorked * rate;
    else
        *Gross = 40 * rate + (hoursWorked - 40) * 1.5 * rate;
    return;
    }
    
    
    
    int calcTaxes (int Gross, int* stateTax, int* federalTax)
    {
    *stateTax = .06 * Gross;
    if (Gross <= 200)
      *federalTax = 0;
    else
      if ((201 <= Gross) || (Gross <= 300))
        *federalTax = .05 * Gross;
      else
        if ((302 <= Gross) || (Gross <= 350))
          *federalTax = .08 * Gross;
        else
          if ((351 <= Gross) || (Gross <= 400))
            *federalTax = .1 * Gross;
          else
            if (400 < Gross)
              *federalTax = .15 * Gross;
            else
              printf ("Invalid Gross");
    return;
    }
    
    
    
    int calcFICA (int Gross, int* FICA)
    {
    *FICA = .0707 * Gross;
    return;
    }
    
    
    
    int calcNetPay (int Gross, int stateTaxes, int federalTaxes, int FICA, int* NetPay)
    {
    *NetPay = Gross - stateTaxes - federalTaxes - FICA;
    return;
    }
    
    
    
    void print_them (int emplNum, int Gross, int stateTax, int federalTax, int FICA, int NetPay)
    {
    printf ("Employee number: %4d\n", emplNum);
    printf ("Gross:  %4d\n", Gross);
    printf ("State Tax:  %4d\n", stateTax);
    printf ("Federal Tax:  %4d\n", federalTax);
    printf ("FICA:  %4d\n", FICA);
    printf ("Net Pay:  %4d\n", NetPay);
    return;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Garbage values almost always mean you're using a variable before initializing it. If you compile with warnings on, your compiler will likely tell you as much.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    I researched a bit about the warning my compiler gave me and figured it out.
    Thanks for pointing me in the right direction, quzah!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing values from Edit Box into an array
    By E_I_S in forum C++ Programming
    Replies: 10
    Last Post: 06-05-2008, 06:24 AM
  2. putting values into an array
    By zdream8 in forum C Programming
    Replies: 15
    Last Post: 05-21-2008, 11:18 PM
  3. can't assign proper values to an array of string
    By Duo in forum C Programming
    Replies: 1
    Last Post: 04-04-2005, 06:30 AM
  4. Replies: 1
    Last Post: 02-03-2005, 03:33 AM
  5. Garbage values
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 06-03-2002, 05:17 PM

Tags for this Thread