#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    1
    Rep Power
    0

    Cannot redeclare funcion error HELP!


    I keep getting errors when I try to compile stating I cannot redeclare funcion (Get_input). I don't know what I am doing wrong HELP!!

    #include <stdio.h>

    #define EMP_DATA 5
    #define OT_RATE 1.5
    #define BASE_PAY 40.0

    void Get_input(int clock_number[], float hours_worked[])
    {
    /* Local Variable Declaration*/
    int counter;

    /* Prompts for number of hours worked and stores them in an array*/

    for (counter=0; counter < EMP_DATA; ++counter)
    {
    printf( "Please enter the number of hours worked for clock# ");
    printf("%06li ", clock_number[counter]);
    scanf ("%f", hours_worked[counter]);
    printf("\n");

    }
    printf("\n");

    }/* end Get_input */




    void Gross_pay_calc (float hours_worked[], float wage_rate[], float gross_pay[], float OT[])
    {
    /* Local Variable Declaration*/
    int i; /* array index*/


    for (i = 0; i < EMP_DATA; ++i)
    {
    /*check to see if hours worked are less than or equal to forty hours.*/

    if (hours_worked[i] <= BASE_PAY)
    /* calculate gross pay */
    gross_pay[i] = hours_worked[i] * wage_rate[i];

    else /*calculate gross pay with overtime*/

    OT[i] = hours_worked[i] - BASE_PAY;
    gross_pay[i] = (hours_worked[i] - OT[i]) * wage_rate[i] + (OT[i] * wage_rate[i]) * OT_RATE;
    }

    } /* end Gross_pay_calc */



    void Display_results ( unsigned long int clock_number[], float wage_rate[], float hours_worked[], float OT[], float gross_pay[])
    {
    /* Local Variable Declaration*/
    int i; /* array index*/



    /* Print employee information on screen*/
    printf ("\n\n");
    printf ("----------------------------------------------\n");
    printf ("Clock#\t Wage\t Hours\t OT\t Gross \n");
    printf ("----------------------------------------------\n");

    for (i = 0; i < EMP_DATA; ++i) /* loops elements in array and displays table format for the specified number of times*/

    printf ("%06ul\t %.2f\t %.2f\t %.2f\t %.2f\n\n\n", clock_number[i], wage_rate[i], hours_worked[i], OT[i], gross_pay[i]);

    }/* end Display_results*/


    /*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

    main()

    {
    /*declaring variables*/


    unsigned long int clock_number[EMP_DATA] = {98401ul, 526488ul, 765349ul, 34645ul, 127615ul};/*array of employee clock number*/
    float wage_rate[EMP_DATA] = {10.60f, 9.75f, 10.50f, 12.25f, 8.35f}; /*static array of hourly wage*/
    float hours_worked[EMP_DATA] = {0.0, 0.0, 0.0, 0.0, 0.0}; /* array of hours worked per week*/
    float OT[EMP_DATA] = {0.0, 0.0, 0.0, 0.0, 0.0}; /*overtime hours worked per week*/
    float gross_pay[EMP_DATA] ; /*calculated gross pay per week*/


    /*Function call to get input from user*/

    Get_input(clock_number,hours_worked);

    /*Function call to calculate gross pay, including overtime, if any*/
    Gross_pay_calc(wage_rate, hours_worked, OT, gross_pay);

    /*Function call to display results to the screen in table format*/
    Display_results_array (clock_number, wage_rate, hours_worked, OT, gross_pay);

    }
  2. #2
  3. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    You have Get_input defined as so:

    void Get_input(int clock_number[], float hours_worked[])

    which requires an array of ints and an array of floats as parameters. You call the function like so:

    Get_input(clock_number,hours_worked);

    and the parameters passed are delcared as so:

    unsigned long int clock_number[EMP_DATA] = {98401ul, 526488ul, 765349ul, 34645ul, 127615ul};/*array of employee clock number*/
    float hours_worked[EMP_DATA] = {0.0, 0.0, 0.0, 0.0, 0.0}; /* array of hours worked per week*/


    You are trying to pass in an array of unsigned long int as a parameter that requires an array of int. Automatic typecasting can only work on ONE simple type at a time - not an entire array. In other words, the compiler cannot typecast an array of unsigned long int to an array of int. When the compiler cannot type cast for you, you have to typecast manually (which is not possible for an array) or pass in the same type.

    ----------------

    Once I change the paramters to be the same type, and rename your function call to Display_results_array to the proper function name (Display_results), it compiles fine.
    Last edited by Jason Doucette; March 17th, 2003 at 01:36 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Hi,

    How about putting your code in between code tags:

    code

    /code

    (include brackets around the tags)

    to preserve the formatting and making it easier to read. Also, it's always helpful to include the error message, and what line it occurred on?
    Last edited by 7stud; March 17th, 2003 at 01:43 PM.

IMN logo majestic logo threadwatch logo seochat tools logo