I am writing a program for my C programming class that is supposed to have basic ATM functions, but the problem is when I compile I get an error message saying "Undefined reference to 'Printf'." I have checked my printf statements and cannot find the problem. If anyone could help me out it would be much appreciated. Thanks
Code:
#include <stdio.h>
#define SCREEN_HEIGHT 80 // Number of newlines to print out
#define MAXLINE 100 // Maximum user input characters
// Function prototypes
void displayMenu(void);
float checkBalance(int acctNum);
int getAccountIndex(int acctNum);
int transferFunds(int acct1, int acct2,float amt);
int withdrawCash(int acctNum, int amt);
int getline(char s[], int lim);
void printError(char errNo);
// Global List of account numbers
int accountList[] = {1234, 5289, 8744, 6912, 3421, 9658, 1487, 1147, 5732};
// Global List of corresponding balances for each account (in same order of account number above)
float balanceList[] = {4798.32,19628.89,150.78,100.00,6742.00,874.05,543.91,578963.45,8943.12};
int main()
{
int accountNumber;
char line[MAXLINE];
double atof(char []);
int i;
int c;
char userInput;
// Get the persons account number (like putting in a debit card)
printf("Please enter your account number: ");
getline(line,MAXLINE);
accountNumber = atof(line);
if (accountNumber != accountList[i])
{
printError(-12);
}
do
{
displayMenu(); // read menu option using getline and atof functions
getline(line, MAXLINE);
int menuOption = atof(line);
switch(menuOption)
{
case 1:
checkBalance(accountNumber);
break;
case 2:
printf("Please enter the Account Number to transfer to");
getline(line,MAXLINE);
int x = atof(line);
printf("How much would you like to transfer?");
getline(line,MAXLINE);
int y = atof(line);
float z = transferFunds(accountNumber, x, y);
if (z != 0)
printError(z);
break;
case 3:
Printf("How much would you like to Withdraw?");
getline(line, MAXLINE);
int a = atof(line);
float b = withdrawCash(x,y);
if (b < 0)
printError(a);
else
printf("Cash despensing complete!");
break;
default:
printf("Error");
break;
}
} while (userInput != 4);
return 0; // Assume successful completion of program if we made it here
}
/* displayMenu: display the menu options */
void displayMenu(void)
{
int j;
char userInput;
// Clear out the screen contents
for(j=0;j<=SCREEN_HEIGHT;j++)
printf("\n");
// Print the Menu Options
printf("1. Check Balance\n");
printf("2. Transfer Funds\n");
printf("3. Withdraw Cash\n");
printf("4. Exit\n");
}
/* checkBalance: return the balance of the specified account */
float checkBalance(int acctNum)
{
int x;
x = getAccountIndex(acctNum);
return balanceList[x];
}
/* getAccountIndex: get the array index for the specified account */
int getAccountIndex(int acctNum)
{
int i;
for (i=0; i< sizeof(accountList)/sizeof(int); i++)
{
if (acctNum == accountList[i]) // make sure account number is on the list
{
return i;
}
}
return -1;
}
/* transferFunds: transfer funds from acct1 to acct2 in the amount of amt */
int transferFunds(int acct1, int acct2, float amt)
{
int i;
int x;
int y;
float newBalance1;
float newBalance2;
x = getAccountIndex(acct1); // get each of the account indices.
y = getAccountIndex(acct2);
if (acct1 < amt) // verify there is enough money in account
return -11;
if (acct2 != accountList[i]) // make sure the account exists
return -12;
newBalance1 = acct1 + amt;
newBalance2 = acct2 - amt;
return 0;
}
/* withdrawCash: deduct amount from account and show message for dispensing */
int withdrawCash(int acctNum, int amt)
{
int newBalance;
int x;
x = getAccountIndex(acctNum);
if (acctNum < amt) // make sure the account has enough money in it
return -11;
// Debit the amount from the account and print dispensing cash
newBalance = acctNum - amt;
printf("\nDispensing Cash...\n");
return 0;
}
/* atof: convert string s to double */
double atof(char s[])
{
double val, power;
int i, sign;
for( i=0; isspace(s[i]); i++) /* skip white space */
;
sign = (s[i] == '-') ? -1 : 1;
if( s[i] == '+' || s[i] == '-')
i++;
for( val=0.0; isdigit(s[i]);i++)
val = 10.0 * val + (s[i]-'0');
if( s[i] =='.')
i++;
for( power=1.0; isdigit(s[i]); i++)
{
val = 10.0 * val + (s[i]-'0');
power *= 10.0;
}
return sign * val/power;
}
/* getline: get line into s, return length */
int getline(char s[], int lim)
{
int c,i;
i=0;
while( --lim > 0 && (c=getchar()) != EOF && c!= '\n')
{
s[i++] = c;
}
if(c == '\n')
{
s[i++] = c;
}
s[i] = '\0';
return i;
}
/* printError: print the corresponding error message */
void printError(char errNo)
{
// Based on input, print appropriate error message
switch(errNo)
{
case -11: printf("I'm sorry, you do not enough money to handle this transfer.\n");
case -12: printf("I'm sorry, the account number you entered does not exist.\n");
case -13: printf("Menu Options INVALID\n");
default: // Print a generic error for anything else calling this function
printf("ERROR\n");
break;
}
}