未定义的函数调用引用?

时间:2013-10-22 19:02:17

标签: c function reference call undefined

我认为我唯一的问题是这个未定义的引用......以及我所有的函数调用。我之前已经完成了功能和指针,并试图遵循相同的格式,但我迷失了我的错误:/我将它们全部废弃,定义了我的指针,并给了它们正确的类型......它只是说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;
    }

2 个答案:

答案 0 :(得分:1)

将您的功能从main()功能中移除。

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

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

void menuFunction (float *menup)
{
  ...
  ...   

除此之外,您的程序还有很多错误。纠正它们。

答案 1 :(得分:1)

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


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