gpt4 book ai didi

c - C 中未解析的外部符号

转载 作者:太空宇宙 更新时间:2023-11-04 05:37:01 24 4
gpt4 key购买 nike

未解析的外部符号错误阻止了我的代码的编译。它特别提到了 main 中调用的两个函数。这些功能是我试图创建的开关的一部分,它仍在 build 中。如果有人对我如何修复错误或改进我的代码有任何建议,请告诉我并提前感谢您。仅供引用-我已经搜索过类似的问题,但它们并不特定于我的问题...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//This is a macro intended for use with the emplyName array.
#define SIZE 20

//This struct has all the varibles that I will be using in my functions
typedef struct person
{
char* emplyName[5][SIZE];
float emplyHours[5];
float emplyRate[5];
float emplyGross[5];
float emplyBase[5];
float emplyOvrt[5];
float emplyTax[5];
float emplyNet[5];
float emplyTotal[5];
}input;

void menu(void);
void employeeInfo(input* emply);
void editEmployees(input* emply);
void print(input* emply);

int main(void)
{
struct person *payroll={""};
int choice = 0;
menu();
scanf_s("%c", &choice);
switch (choice){
case '1':
employeeInfo(payroll);
break;
case '2':
editEmployees(payroll);
break;
case '3':
print(payroll);
break;
case '4':
break;
default:
printf("Invalid entry\n");
}
system("pause");
}

void employeeInfo(input *emply)
{
int i=0;
do {
printf("Enter employee name.\n");
scanf_s("%s", &emply->emplyName[i]);
printf("Enter employee hours.\n");
scanf_s("%f", &emply->emplyHours[i]);
printf("Enter Hourly rate.\n");
scanf_s("%f", &emply->emplyRate[i]);
} while (++i <= 5);

void calculations(input *emply);/*Write a method that calculates the gross, base and overtime pay, pass by reference.*/
{
int i;
i = 0;
for (i = 0; i < 5; i++){
if (emply->emplyHours[i] > 40) {
emply->emplyOvrt[i] = (emply->emplyHours[i] - 40) * (emply->emplyRate[i] * 1.5);
}
emply->emplyGross[i] = (((emply->emplyHours[i])*(emply->emplyRate[i])) + emply->emplyOvrt[i]);
emply->emplyBase[i] = (emply->emplyGross[i]) - (emply->emplyOvrt[i]);
emply->emplyTax[i] = ((emply->emplyGross[i])*.2);
emply->emplyNet[i] = (emply->emplyGross[i]) - (emply->emplyTax[i]);
emply->emplyTotal[0] += emply->emplyGross[i];
}


}


void print(input *emply);
{
int i;
for (i = 0; i < 5; i++)
{


printf("Employee Name:%s\n", emply->emplyName[i]);
printf("Hours Worked:%.2f\n ", emply->emplyHours[i]);
printf("Hourly Rate:%.2f\n", emply->emplyRate[i]);
printf("Gross Pay:%.2f\n", emply->emplyGross[i]);
printf("Base Pay:%.2f\n", emply->emplyBase[i]);
printf("Overtime Pay:%.2f\n", emply->emplyOvrt[i]);
printf("Taxes Paid:%.2f\n", emply->emplyTax[i]);
printf("Net Pay:%.2f\n", emply->emplyNet[i]);
}
printf("Total paid to all employees : %.2f\n", emply->emplyTotal[0]);
}
void editEmployees(input*emply);
{
char edit;
int i;
printf("which employee would you like to edit?\n");
for (i = 0; i < 5; i++){
printf("%d.%s", i + 1, emply->emplyName[i]);
}
scanf_s("%c", &edit);
switch (edit){
case '1':
printf("Enter employee name.\n");
scanf_s("%s", &emply->emplyName[0]);
printf("Enter employee hours.\n");
scanf_s("%f", &emply->emplyHours[0]);
printf("Enter Hourly rate.\n");
scanf_s("%f", &emply->emplyRate[0]);
}
}



}

void menu(void){
printf("Main Menu\n");
printf("1. Add Employee\n");
printf("2. Edit Employee\n");
printf("3. Print Employee\n");
printf("4. Print All EMployees\n");
printf("0. exit\n");

}

最佳答案

您将 editEmployees()print() 定义为局部于 employeeInfo()

  1. 这对程序的其余部分隐藏了它们。
  2. 这不是标准 C。
  3. 如果您正确地缩进了代码,您自己很可能会注意到这一点。

calculations() 也是如此。

关于c - C 中未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31764508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com