Functions problem. *Need Help*

This is a discussion on Functions problem. *Need Help* within the C Programming forums, part of the General Programming Boards category; ok this program has been driving me nutz. I have it working perfectly just useing arrays without functions. But when ...

  1. #1
    Unregistered
    Guest

    Question Functions problem. *Need Help*

    ok this program has been driving me nutz. I have it working perfectly just useing arrays without functions. But when i go cut n paiste it into functions and try to get it working right it throws up at me. can anyone help mw out? getting lots of really odd errors.

    /* The program determines the gross pay and ouputs the following
    format:
    --------------------------------------------------------------
    Clock# Wage Hours OT Gross
    --------------------------------------------------------------
    098401 10.60 51.0 11.0 598.90
    526488 9.75 42.5 2.5 426.56
    765349 10.50 37.0 0.0 388.50
    034645 12.25 45.0 5.0 581.88
    127615 8.35 0.0 0.0 0.00*/


    #include <stdio.h>
    #define ARRAY_SIZE 5
    void Get_Hours(long int[], float[],int);
    void Calculate_Gross_Pay(float[], float[], float[], float[], int);
    void Calculate_Overtime_Pay();
    void Print_Header();
    void Print_Results();
    /************************************************** ************************/
    /* Function Print_Header - */
    /* */
    /* Purpose: This function will print the header for the output */
    /* and send it to the screen. */
    /* */
    /* Parameters: none */
    /* */
    /* Returns: void */
    /************************************************** ************************/

    void Print_Header (void)
    {
    printf ("--------------------------------------------------------------\n");
    printf ("Clock# Wage Hours OT Gross \n");
    printf ("--------------------------------------------------------------\n");
    }

    /************************************************** ************************/
    /* Function Print_Results */
    /* */
    /* Purpose: This function will print the results of our program */
    /* to the screen following the Print_header function */
    /* */
    /* Parameters: */
    /* */
    /* Returns: void */
    /************************************************** ************************/

    void Print_Results (long int clock_number[], float wages_array[], float hours_array[], float othours_array[], float gross_array[])
    {
    int i;
    for( i = 0; i < 5; ++i)
    {
    printf ("%06i %5.2f %5.1f %5.1f %5.2f\n", clock_number[i], wages_array[i], hours_array[i], othours_array[i], gross_array[i]);
    }
    }
    /************************************************** ************************/
    /* Function Get_Hours */
    /* */
    /* Purpose: This function will */
    /* */
    /* */
    /* */
    /* Parameters: */
    /* */
    /* */
    /* */
    /* Returns: */
    /************************************************** ************************/

    void Get_Hours (long int clock_number[],
    float hours_array[])
    {
    int i;
    for( i = 0; i < 5; ++i)
    {
    printf ("Enter hours for %i", clock_number[i]);
    scanf ("&hours_array[i]);
    }
    }

    /************************************************** ************************/
    /* Function Calculate_Gross_Pay */
    /* */
    /* Purpose: This function will calculate the gross pay for five */
    /* employees. It will add to the gross pay any overtime */
    /* pay if necessary. */
    /* */
    /* Parameters: wages_array - array of wage rates for each employee */
    /* hours_array - array of # of hours each employee worked */
    /* otpay_array - array of overtime pay for each employee */
    /* gross_array - an array of the calculated gross pay for */
    /* each employee. */
    /* emp_count - the number of total employees */
    /* */
    /* Returns: Nothing since the gross_pay array is passed by reference */
    /************************************************** ************************/

    void Calculate_Gross_Pay (float wages_array[], float hours_array[], float otpay_array[],
    float gross_array[], int emp_count)

    {
    int i;

    for (i = 0; i <= 40)

    /* calculate gross pay */
    gross_array[i] = 40 * wages_array[i] + otpay_array[i];

    else


    gross_array[i] = wages_array[i] * hours_array[i];

    }

    }





    /************************************************** ************************/
    /* Function Calculate_Overtime_Pay */
    /* */
    /* Purpose: This function will calculate the gross pay for five */
    /* employees. It will add to the gross pay any overtime */
    /* pay if necessary. */
    /* */
    /* Parameters: wage - rate of pay for the employee */
    /* hours - # of hours the employee worked */
    /* ot_pay - overtime pay for the employee */
    /* */
    /* Returns: gross pay (including any overtime pay) for the employee */
    /************************************************** ************************/
    void Calculate_Overtime_Pay ()
    {
    if (othours_array[i] > 40)
    return (othours_array[i] - 40);
    else /* no overtime was worked */
    return (othours_array[i]=0.0);
    }
    void main ()
    /* Create and fill Clock# Array*/
    int clock_number[ARRAY_SIZE];
    clock_number[0] =98401;
    clock_number[1] =526488;
    clock_number[2] =765349;
    clock_number[3] =34645;
    clock_number[4] =127615;
    /*Create and fill Wages Array*/
    float wages_array[ARRAY_SIZE];
    wages_array[0] =10.6f;
    wages_array[1] =9.75;
    wages_array[2] =10.5;
    wages_array[3] =12.25;
    wages_array[4] =8.35f;

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    11
    right off hand, I don't see a main () .
    all functions need to be called from the main ()

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    11
    found it

    void main () {
    /* Create and fill Clock# Array*/
    int clock_number[ARRAY_SIZE];
    clock_number[0] =98401;
    clock_number[1] =526488;
    clock_number[2] =765349;
    clock_number[3] =34645;
    clock_number[4] =127615;
    /*Create and fill Wages Array*/
    float wages_array[ARRAY_SIZE];
    wages_array[0] =10.6f;
    wages_array[1] =9.75;
    wages_array[2] =10.5;
    wages_array[3] =12.25;
    wages_array[4] =8.35f;

    Get_Hours (clock_number[], hours_array[]) ;
    Calculate_Gross_Pay (wages_array[], hours_array[], otpay_array[], gross_array[], emp_count) ;
    Calculate_Overtime_Pay () ; /* othours is not global and will need to be passed to the funtion. */




    } /* end of main */

  4. #4
    Unregistered
    Guest

    Question hmmm....

    well i know that i didn't put the calls for the functions in yet. But I am getting errors in the functions that i can see why.
    example in my Get_hours function i get
    C:\Documents and Settings\David Moore\Desktop\C Class\Homework 5b.cpp(92) : error C2001: newline in constant

    which points to scanf ("&hours_array[i]);

  5. #5
    Unregistered
    Guest

    Question Delete this thread please....

    All set. Got most of it working. Thanks to all the 30+ people who viewed this thread

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with functions
    By saliya in forum C Programming
    Replies: 1
    Last Post: 11-05-2007, 09:36 PM
  2. Problem with system(), execl(), etc. functions
    By nickkrym in forum C Programming
    Replies: 5
    Last Post: 05-12-2007, 08:04 AM
  3. Problem: Functions
    By Dmitri in forum C Programming
    Replies: 21
    Last Post: 11-06-2005, 09:40 AM
  4. Problem with pointers and functions
    By Kheila in forum C++ Programming
    Replies: 5
    Last Post: 10-13-2005, 12:40 PM
  5. Problem with functions
    By lizardking3 in forum C++ Programming
    Replies: 4
    Last Post: 09-22-2003, 04:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21