gpt4 book ai didi

c - 对函数调用的 undefined reference ?

转载 作者:行者123 更新时间:2023-12-02 20:18:48 26 4
gpt4 key购买 nike

我认为我唯一的问题是这个 undefined reference ......以及我所有的函数调用。我之前做过函数和指针,并尝试遵循相同的格式,但我不知道自己做错了什么:/我将它们全部作废,定义了我的指针,并给了它们正确的类型......它只是说 4 个错误,指出“未定义对 __menuFunction 的引用”等...

#include<stdio.h>

void menuFunction(float *);
void getDeposit(float *, float *);
void getWithdrawl(float *, float *);
void displayBalance(float );


int main()
{
float menu, deposit,withdrawl, balance;
char selection;

menuFunction (& menu);
getDeposit (&deposit, &balance);
getWithdrawl(&withdrawl, &balance);
displayBalance(balance);



void menuFunction (float *menup)
{

printf("Welcome to HFCC Credit Union!\n");
printf("Please select from the following menu: \n");
printf("D: Make a Deposit\n");
printf("W: Make a withdrawl\n");
printf("B: Check your balance\n");
printf("Or Q to quit\n");
printf("Please make your slelction now: ");
scanf("\n%c", &selection);
}

switch(selection)
{
case'd': case'D':
*getDeposit;
break;
case 'W': case'w':
*getWithdrawl;
break;
case'b': case'B':
*displayBalance;
}

void getDeposit(float *depositp, float *balancep)
{
printf("Please enter how much you would like to deposit: ");
scanf("%f", *depositp);
do
{
*balancep = (*depositp + *balancep);
} while (*depositp < 0);

}

void getWithdrawl(float *withdrawlp, float *balancep)
{
printf("\nPlease enther the amount you wish to withdraw: ");
scanf("%f", *withdrawlp);
do
{
*balancep = (*withdrawlp - *balancep);
} while (*withdrawlp < *balancep);

}


void displayBalance(float balance)
{
printf("\nYour current balance is: %f", balance);
}





return 0;
}

最佳答案

您的 menuFunction() getDeposit()getWithdrawl() 是在 main() 中定义的 body 。 ANSI-C 不支持嵌套函数。让代码正常工作的最简单方法是在全局范围内定义函数。

<小时/>

[更新]但不要忘记修复代码中的其他错误(例如,menuFunction() 中的语句变量是一个未解析的符号,它必须声明为全局变量或者应该作为参数发送到函数中。我建议你阅读K&R,它是C程序员的经典之作!

关于c - 对函数调用的 undefined reference ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19526169/

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