C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 17th, 2003, 01:07 PM
Karenivan Karenivan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 1 Karenivan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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);

}

Reply With Quote
  #2  
Old March 17th, 2003, 01:33 PM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
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.

Reply With Quote
  #3  
Old March 17th, 2003, 01:40 PM
7stud 7stud is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2001
Posts: 1,365 7stud User rank is Private First Class (20 - 50 Reputation Level)7stud User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 9 m 25 sec
Reputation Power: 14
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Cannot redeclare funcion error HELP!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap