Reputation: 33
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;
}
Upvotes: 3
Views: 1261
Reputation: 2787
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!
Upvotes: 1
Reputation: 106102
Take your functions out of the main()
function.
int main()
{
float menu, deposit,withdrawl, balance;
char selection;
menuFunction (& menu);
getDeposit (&deposit, &balance);
getWithdrawl(&withdrawl, &balance);
displayBalance(balance);
}
void menuFunction (float *menup)
{
...
...
Beside this your program has many errors. Correct them.
Upvotes: 1