2013-10-22 212 views
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; 
    } 
+1

你为什么在您的main()? –

回答

1

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


[UPD],但不要忘了修复代码中的错误的另一个(例如,声明menuFunction()变量是一个未解决的符号,它必须被声明为全局变量或应该被送入该函数作为参数。我劝你还是已读k & R,它是C程序员经典!

+1

@Gangadhar嗯,是的定义函数:) 谢谢 – Netherwire

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

oohhhhhhh ....谢谢! – Jnr