2013-10-22 98 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