这是我的代码:
#include #include #include #include int hours; //hours worked. double rate; //Hourly rate double regular; //Regular pay double overtime; //how many hours the user worked overtime. double gross; //Gross salary double federal; //Federal tax of 27% double medical; //medical insurance, 14% double net; // Pay after federal tax and medical insurance is taken out. char c[1]; int Running = 1; int f = -1; void option(int opt); main(void) { void workStats(void); //Function that will collect user's number of hours and how much they make an hour. void regularPay(void); void grossPayWithOvertime(void); void totalPayTakingOutTaxes(void); void printMenu(void); void printMenu(void); while (Running == 1) { scanf("%d", &f); option(f); printf("n"); } return 0; } void option(int option) { switch (option) { case 1: workStats(); break; case 2: regularPay(); break; case 3: grossPayWithOvertime(); break; case 4: totalPayTakingOutTaxes(); break; case 5: Running = 0; break; default: printf("Sorry, but that was not an option; Please enter one of our choices. Type any number between 1 and 6."); system("pause"); } void printMenu(void); { printf("==========================================================n"); printf("===========Payroll Program==========================n"); printf("============================================================nn"); printf("Things you can do here.n"); printf("n1. Tell us about how much you make and how many hours you work n"); printf("n2. Regular Pay, before taxes are includedn"); printf("n3. Gross PAy (This includes overtime) n"); printf("n4. Net pay (Taxes taken out of Gross Pay) n"); printf("n5. Exit"); printf("Please type the number corresponding to the action you wish to take. n"); } void workStats(void); { printf("Now, how many hours do you work a week?"); scanf("%d", &hours); printf("Please tell me how much you make per hour."); scanf("%lf", &rate); } void regularPay(void); { regular = rate * hours; printf("Regular Pay:%.2lf n ", regular); } void grossPayWithOvertime(void); { overtime = (hours - 40) * (rate * 1.5); printf("Overtime Pay:%.2lf n ", overtime); gross = regular + overtime; printf("Gross Pay:%.2lf n ", gross); } void totalPayTakingOutTaxes(void); { federal = gross * .27; printf("Federal Tax:%.2lf n", federal); medical = gross * .14; printf("Medical Insurance :%.2lf n ", medical); net = gross - (federal + medical); printf("Net Pay:%.2lf n ", net); system("pause"); } }
问题是当我尝试编译时它无法识别我的函数调用。 清理和重建并没有解决这个问题,(我今天刚编程,所以它没有坐在那里或任何东西)我没有我在这段代码中引用的任何外部文件,所以这也不是问题。 任何帮助深表感谢。 完整错误: https : //puu.sh/wKn4n/00f95f3032.png
您有两个问题:第一个是您在main
函数的范围内声明原型(顺便说一下,您忘记给出返回类型)。 原型应在全球范围内声明。
第二个问题更糟糕,因为你正在做一些完全无效的事情,那就是在option
函数中定义函数。 当然,它们也应该在全球范围内定义(实施)。 定义嵌套函数(其他函数内的函数)无效C.
文件的整体结构应如下所示:
#include #include int globalvar; // if you must have globals; you should try to avoid them static void workStats(void) { // body of workStats here } static void regularPay(void) { // body of regularPay here } // and so on like that, for all functions besides main int main(void) { // body of main here // you don't need to redeclare the functions }
以上就是c/c++开发分享C:在function选项中找到未解析的外部符号(函数名称)。 LINK 2019错误相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/519307.html