Created
May 19, 2012 18:12
-
-
Save kgleeson/2731795 to your computer and use it in GitHub Desktop.
ATM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void print_options(){ | |
printf(" Please choose an option \n"); | |
printf(" 1: Balance Enquiry \n"); | |
printf(" 2: Withdraw Funds \n"); | |
printf(" 3: Quit \n"); | |
} | |
void print_welcome(){ | |
printf("--------------------------------------------------------------------------------\n"); | |
printf(" Welcome to the ATM system \n"); | |
} | |
void print_balance(int *balance){ | |
printf("Your balance is: $%d\n", *balance); | |
} | |
int withdraw_funds(int *balance){ | |
int withdrawl = 0 ; | |
do { | |
if(withdrawl > *balance){ | |
printf("Insufficent funds\n"); | |
} | |
printf("Your current balance is: $%d\n", *balance); | |
printf("Please enter the amount to withdraw:\n$"); | |
scanf("%d", &withdrawl); | |
} while (withdrawl > *balance && balance > 0); | |
*balance = *balance - withdrawl; | |
} | |
int check_option(){ | |
int option; | |
do { | |
printf("Please enter a correct choice\n"); | |
scanf("%d", &option); | |
} while(option < 1 || option > 3); | |
return option; | |
} | |
int main(){ | |
int state = 0 ; | |
int welcomed = 0; | |
int balance = 1000; | |
print_welcome(); | |
do { | |
print_options(); | |
if(welcomed == 0){ | |
printf("--------------------------------------------------------------------------------\n"); | |
welcomed = 1; | |
} | |
int optionSelected = check_option(); | |
// printf("Option: %d\n", optionSelected); | |
if (optionSelected == 1){ | |
print_balance(&balance); | |
} | |
if (optionSelected == 2){ | |
withdraw_funds(&balance); | |
printf("Your new balance is: $%d\n\n", balance); | |
} | |
if (optionSelected == 3){ | |
state = 1;} | |
} while(state == 0); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment