Thread: Program that replicates an ATM machine

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    44

    Program that replicates an ATM machine

    The customer will be assigned a random number for his/her balance.


    First, the customer is prompted to enter his personal identification number pin (for this case study, we test only if this pin is formed by 4 digits! otherwise, a message like “Invalid PIN, try again . . .” will be displayed) and the user is re-prompted to enter the pin. The customer is given three chances to enter his pin. If he/she fails during the three trials you display a message like “Sorry you can’t continue, contact your bank for assistance!”


    If the pin is correct (formed by 4 digits), then the system will ask the customer for the receipt ( 1 for YES and 2 for NO ) and a menu will displayed containing five possible options to choose from: Fast Cash, Deposit, Withdraw, Balance and Get Card Back.


    Here is the explanation of each of the 5 options:


    Get Card Back: Display the message “Goodbye! “and exit the program.


    Fast Cash: Let the customer choosing the amount of cash from a menu similar to the following:
    Press:
    1 --> $20.00 $40.00 <-- 2
    3 --> $80.00 $100.00 <-- 4


    Withdraw: Prompt the user for the amount of money he/she would like to withdraw and make the sure that he/she has enough money for that!


    Deposit: Prompt the customer for the amount of deposit.


    Balance: Just display the amount of money the customer has.


    Don’t forget to print the receipt if the customer wants one.


    Sample execution: bolded text represents the user entry


    Virtual Bank at West
    WELCOME


    Enter Pin: 245
    Invalid PIN, Re-enter Pin: 5487
    (clear screen )


    Receipt y or Y -> Yes No <- n or N
    Enter choice: N


    (Clear screen)


    CHOOSE FROM THE FOLLOWING


    1 -> Fast Cash Withdraw <- 2
    3 -> Deposit Check Balance <- 4
    5 -> Get Card Back


    Enter your choice: 4

    (Clear screen)
    Your Balance is : $124.32

    1 -> Another Transaction Get Card Back <- 2

    Enter your choice: 1


    (Clear screen)


    CHOOSE FROM THE FOLLOWING


    1 -> Fast Cash Withdraw <- 2
    3 -> Deposit Check Balance <- 4
    5 -> Get Card Back


    Enter your choice: 2


    (Clear screen )


    Enter amount (enter 0 to cancel): 300.00
    Sorry not enough balance
    Enter amount (enter 0 to cancel): 30.00
    Take your cash…


    (Clear screen)


    Your Balance is: $124.32

    1 -> Another Transaction Get Card Back <- 2

    Enter your choice: 1


    (Clear screen)


    CHOOSE FROM THE FOLLOWING


    1 -> Fast Cash Withdraw <- 2
    3 -> Deposit Check Balance <- 4
    5 -> Get Card Back


    Enter your choice: 8
    Invalid Entry


    (Clear screen)


    CHOOSE FROM THE FOLLOWING


    1 -> Fast Cash Withdraw <- 2
    3 -> Deposit Check Balance <- 4
    5 -> Get Card Back


    Enter your choice: 5


    (Clear screen)



















    Im not looking for a huge block of code answering this problem. Im looking for guidance on how I would construct this program, would I start with a menu than from that menu use different functions for each option?

    Just any advice would help me!

  2. #2
    Old Fashioned
    Join Date
    Nov 2016
    Posts
    134
    Ok so when I first read it, I was going to say I would start by making a "Customer" struct which basically has the customer info like balance, PIN, etc...

    However, after reading more closely, it looks like this is simply a "view" or "front-end" application. They're asking you to generate random numbers every time the program is opened for the balance, which means, no file IO is needed at all. And you don't need to store PINs either since the PIN is pretty useless and really the system is just checking for "any number that is 4 characters long." So this makes the application very simple. Work on it feature-by-feature. First, make a struct called User with a "int balance" and something like "unsigned int numberOfLoginAttempts."

    Then once you've got that defined, I would start getting to work on the first feature by creating a "userLogin()" function which does what the assignment wants. Then when the program starts in main, call up that userLogin() function immediately, handle the login, and then work procedurally through from there. After the login will be the "promptForReceipt()" and finally "displayMainMenu()" which will printf the options to the user, scan in their choice, and then just do a switch-case based upon their choice and fire different functions from there....

    That's how I would do it. Some people might just slap it all in main but I like to organize and modularize my code. Just take it one step at a time and work out the logic piece by piece then connect the dots. Gosh, now you got me wanting to build this little app. Wish I had more time right now and I would!
    Last edited by Asymptotic; 12-10-2016 at 04:41 PM.

  3. #3
    Registered User
    Join Date
    Feb 2016
    Posts
    44
    Quote Originally Posted by Asymptotic View Post
    Ok so when I first read it, I was going to say I would start by making a "Customer" struct which basically has the customer info like balance, PIN, etc...

    However, after reading more closely, it looks like this is simply a "view" or "front-end" application. They're asking you to generate random numbers every time the program is opened for the balance, which means, no file IO is needed at all. And you don't need to store PINs either since the PIN is pretty useless and really the system is just checking for "any number that is 4 characters long." So this makes the application very simple. Work on it feature-by-feature. First, make a struct called User with a "int balance" and something like "unsigned int numberOfLoginAttempts."

    Then once you've got that defined, I would start getting to work on the first feature by creating a "userLogin()" function which does what the assignment wants. Then when the program starts in main, call up that userLogin() function immediately, handle the login, and then work procedurally through from there. After the login will be the "promptForReceipt()" and finally "displayMainMenu()" which will printf the options to the user, scan in their choice, and then just do a switch-case based upon their choice and fire different functions from there....

    That's how I would do it. Some people might just slap it all in main but I like to organize and modularize my code. Just take it one step at a time and work out the logic piece by piece then connect the dots. Gosh, now you got me wanting to build this little app. Wish I had more time right now and I would!
    I know they want me to generate random numbers everytime, Im having trouble keeping that random number and being able to run it through the entire program consistently.

    Could someone give me a brief pseudo code for what this would look like? (Or a possibility)

  4. #4
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,687
    Show us what you have done so far and we can help you further. If you want to keep the random number and never change it, then consider making it a constant. However, a constant cannot be modified by another part of the code. So you could use an array whose elements are randomly assigned with each iteration of the program.
    Double Helix STL

  5. #5
    Old Fashioned
    Join Date
    Nov 2016
    Posts
    134
    So to pass the number through your code, you can just use function arguments... You could potentially use global variables as well, but that is much more susceptible to bugs/less safe generally. This is the 2 in action in pseudocode like you asked:

    OPTION 1: Passing the account balance as function arguments:
    Code:
    
    struct Customer{
    int account_balance;
    };
    
    int main(){
    
    /*This is just an example, you can set up the random number to your liking of course*/
    srand(time(NULL));
    int accountBalance = rand();
    struct Customer *user = malloc(sizeof(struct Customer)); //New up a new customer struct on the heap
    user->account_balance = accountBalance;
    Now, for the rest of the application, you can simply code your functions to accept a struct Customer *ptr as an argument and that way you will have that generated account balance until the program is terminated. You could simplify it without a struct as well, but I used a struct in case you had some other data you wanted to pass around because that'll make it easier. Don't forget to free(user) when appropriate as well after you no longer need it. Here's an example of usage:

    Code:
    //In header
    void depositBalance(struct Customer *cPtr);
    
    //In .c file:
    
    void depositBalance(int amountToDeposit, struct Customer *cPtr){
    
    cPtr->account_balance += amountToDeposit;
    
    printf("Transaction complete!\n");
    return;
    }

    Option 2 is as he mentioned above, use a global variable which is literally just assigning something like int accountBalance = rand() outside of any function, now all functions in the program can access that variable and read/modify it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Slot Machine program c++ bug
    By nobo707 in forum C++ Programming
    Replies: 12
    Last Post: 09-23-2009, 07:29 PM
  2. Replies: 3
    Last Post: 11-21-2008, 10:21 AM
  3. c++ program for ATM machine
    By cplus2x in forum C++ Programming
    Replies: 2
    Last Post: 02-06-2008, 04:35 AM
  4. Replies: 4
    Last Post: 01-18-2008, 07:05 PM
  5. soda machine program
    By robasc in forum C++ Programming
    Replies: 3
    Last Post: 05-01-2006, 05:04 AM

Tags for this Thread