Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to a function call?

I think my only problem this undefined reference to...well all of my function calls. I've done functions and pointers before and tried to follow the same format but I'm lost as to what I'm doing wrong :/ I voided them all, defined my pointers, and gave them the correct types...It just says 4 errors stating "undefined reference to __menuFunction" etc...

#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;
    }
like image 485
Jnr Avatar asked Feb 24 '26 05:02

Jnr


1 Answers

Your menuFunction() getDeposit() and getWithdrawl() are defined in main()'s body. Nested functions aren't supported of ANSI-C. The easiest way to make your code work is to define functions in the global scope.


[Upd.] but don't forget to fix another bugs in your code (for example, statement variable in menuFunction() is an unresolved symbol, it must be declared as global variable or should be sent into the function as an argument. I advise you to read K&R, it is classics for C programmers!

like image 183
Netherwire Avatar answered Feb 26 '26 19:02

Netherwire