3

我认为我唯一的问题是这个未定义的引用......以及我所有的函数调用。我之前做过函数和指针,并尝试遵循相同的格式,但我对自己做错了什么感到迷茫:/我将它们全部作废,定义了我的指针,并给了它们正确的类型......它只是说 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;
    }
4

2 回答 2

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)
{
  ...
  ...   

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

于 2013-10-22T19:05:52.147 回答
1

你的menuFunction() getDeposit()andgetWithdrawl()被定义在main()'s body. ANSI-C 不支持嵌套函数。使您的代码工作的最简单方法是在全局范围内定义函数。


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

于 2013-10-22T19:05:55.940 回答