/* Filename: HW4.c */ /* This program simulates an ATM Machine Menu */ /****************************************************************** * * * Programmer: Matthew Glynn * * Date : 02/15/2007 * * Section Number: B36 * * Filename: HW4.c * * Description: This program simulates the menu system of an ATM * * Machine * * * ******************************************************************/ #include /* library to be used */ /* Declare functions */ void printMenu( void ); void deposit( void ); void withdrawal( void ); void inquiry( void ); /* Declare Global variables */ /* Floating Variables */ float number1; /* global variable used in deposit and withdrawal functions */ float accountvalue = 100; /*start the account with $100.00 */ /* Integer Variable */ int choice; /* Main function */ float main( void ) { /* Display this at start of program */ printf("\n Thank you for opening a bank account with us.\n"); printf(" Currently your balance is $100.00.\n"); do /* Part of a do while statement (do while choice is not equal to 4)*/ {/* start do */ printMenu(); /* CALL FUNCTION PRINTMENU*/ switch ( choice )/* Switch on menu choice entered by user */ { /* Addition */ case 1: deposit();/* CALL FUNCTION DEPOSIT */ inquiry();/* CALL FUNCTION INQUIRY */ break; case 2: withdrawal();/* CALL FUNCTION WITHDRAWAL */ inquiry();/* CALL FUNCTION INQUIRY */ break; case 3: inquiry();/* CALL FUNCTION INQUIRY */ break; case 4: break; default: /* display default when a choice <0 or >4 has been entered */ printf("\n**************************************************\n"); printf(" An invalid entry was made.\n"); printf("\n**************************************************\n"); } } /* end while */ while (choice !=4); /* when an entry of 4 is made, exit program */ return 0; /* indicate program ended successfully */ }/* End funcyion main */ /****************************************************************** * * * Programmer: Matthew Glynn * * Name: printMenu * * Function: This function prints the main menu of the program. * * Algorithm: This function is a series of printf statements. * * Input: none * * Output: changes the global variable choice, so no real output * * * ******************************************************************/ void printMenu( void ) { printf("\n Enter 1 for a Deposit.\n "); printf("Enter 2 for a Withdrawal.\n "); printf("Enter 3 for an Inquiry.\n "); printf("Enter 4 to Exit.\n "); scanf("%d", &choice); printf("\n"); }/* ends function printmenu */ /****************************************************************** * * * Programmer: Matthew Glynn * * Name: deposit * * Function: This function adds money to the account value * * Algorithm: This function returns the sum of account total * * and the deposit * * Input: Global Variables * * * * Output: changes global variables so no real output * * * ******************************************************************/ void deposit( void ) { /* Prompt user for first number */ printf("\n**************************************************\n"); printf(" How much money would you like to deposit?"); printf("\n**************************************************\n"); scanf("%f", &number1); printf("\n"); if (number1 < 0) { printf("\nPlease enter a positive number\n"); } else { accountvalue = accountvalue + number1;/* change account balance */ printf("A deposit of $%.2f has been made to you account.\n", number1); } }/* ends function deposit */ /****************************************************************** * * * Programmer: Matthew Glynn * * Name: withdrawal * * Function: This function subtracts two integers. * * Algorithm: This function returns the sum of account total * * and the withdrawal * * Input: Global Variables * * * * Output: changes global variables so no real output * * * ******************************************************************/ void withdrawal( void ) { printf("\n**************************************************\n"); printf(" How much money would you like to withdraw?"); printf("\n**************************************************\n"); scanf("%f", &number1); printf("\n"); if (number1 < 0 || number1 > accountvalue) { printf("\nPlease enter a positive number that is not greater than your balance\n"); } else { accountvalue = accountvalue - number1;/* change account balance */ printf("A withdrawal of $%.2f has been made from you account.\n", number1); } }/* ends function withdrawal */ /****************************************************************** * * * Programmer: Matthew Glynn * * Name: inquiry * * Function: Displays the account balance * * Algorithm: Displays the account balance * * Input: Global Variables * * * * Output: displayes global variable so no real output * ******************************************************************/ void inquiry( void ) { /* Display the account balance */ printf("\n Your account balance is $%.2f\n" ,accountvalue); }/* ends function inquiry */ /************************************************************************* * Programmed by: Matt Glynn * *************************************************************************/