我不断得到:
期望的标识符或'('“
我已重新启动该项目,以我以前使用功能的家庭作业分配为模型,但无法缓解问题。经过2天的强调,欢迎提出任何建议/建议。
这是我的代码的开始,在main之前。如果需要,我可以添加更多内容。非常感谢!
#include <stdio.h>
/* constants */
#define STD_HOURS 40.0 /* hours per week */
#define SIZE 5 /* employees to process */
#define OT 1.5 /* for overtime calculation */
#define AVERAGE 5 /* for obtaining averages */
/* function to obtain hours worked for employees */
void getHours (long int clock_number[]);
float hours_worked[]; /* array for hours worked */
{
printf("Enter the number of hours worked for employee #%d: ", d + 1);
scanf("%f", &hours_worked[d]);
return (getHours);
}
/* function call to calculate overtime hours */
void overtime_grosspay (float hours_worked[]);
float d; /* overtime calculation variable */
float hourly_wage[]; /* initialize array */
float hours_worked[]; /* array for hours worked */
float overtime_hours[]; /* array for overtime pay */
float gross_pay[]; /* array for gross pay per employee */
{
overtime_hours[d] = hours_worked[d] - STD_HOURS;
gross_pay[d] = hourly_wage[d] * STD_HOURS + (hourly_wage[d] * overtime_hours[d] * OT);
return (overtime_grosspay);
}
/* function call to calculate gross pay */
void regular_grosspay (float hours_worked[]);
float d; /* regular gross variable */
float hourly_wage[]; /* initialize array */
float hours_worked[]; /* array for hours worked */
float overtime_hours[]; /* array for overtime pay */
float gross_pay[]; /* array for gross pay per employee */
{
overtime_hours[d] = 0;
gross_pay[d] = hours_worked[d] * hourly_wage[d];
return (regular_grosspay);
}
/* function call to print */
int main()
{
答案 0 :(得分:2)
您有:
/* function to obtain hours worked for employees */
void getHours (long int clock_number[]);
float hours_worked[]; /* array for hours worked */
{
printf("Enter the number of hours worked for employee #%d: ", d + 1);
scanf("%f", &hours_worked[d]);
return (getHours);
}
void getHours(…)
行以分号结尾;那是一个函数声明。
float hours_worked[];
行是一个数组定义,但是它没有指定数组大小,并且没有前缀extern
,因此无效。
{
因此在代码中没有关系;它不是函数定义的一部分。
作为一个函数定义,作用域中没有d
,并且返回指向该函数的指针是行不通的(类型错误,其中之一是-该函数不应在以下位置返回值)全部!),并且无法将数据提供给调用代码。
您可能需要:
/* function to obtain hours worked for one employee */
float getHours (long clock_number)
{
float hours_worked;
printf("Enter the number of hours worked for employee #%ld: ", clock_number);
scanf("%f", &hours_worked);
return (hours_worked);
}
然后将需要更改您使用此功能的方式。我什至没有看过它之外的代码。
答案 1 :(得分:1)
更改以下内容:
void getHours (long int clock_number[]);
float hours_worked[]; /* array for hours worked */
{
收件人:
void getHours (long int clock_number[])
{
float hours_worked[]; /* array for hours worked */
(请注意,在删除函数声明后,除了移动{the;之外)