Question

In: Computer Science

Please code this in C In this project, we shall simulate the operations of an ATM...

Please code this in C

In this project, we shall simulate the operations of an ATM machine.

Suppose you’re in charge of this simulation and here is a scenario of what is required to do:

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 be 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.3

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)

THANK FOR USING OUR VIRTUAL BANK SYSTEM

GOODBYE. . .

Solutions

Expert Solution

Code:

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

#include <conio.h>

int main() {

    int userChoice, cardPin, pinTries = 0, ch;

    char rt;

    double balance;

    srand(time(NULL));

    balance = rand() % 900 + 100;

    printf("Virtual Bank at West\n\t\tWELCOME ");

    do {

        if (pinTries == 0)

            printf("\nEnter PIN: ");

        else

            printf("INVALID PIN, Re-enter PIN: ");

        scanf("%d", & cardPin);

        pinTries++;

        if (cardPin >= 1000 && cardPin < 10000) {

            system("cls");

            printf("Receipt y or Y --> YES\t\tn or N --> No\nEnter Choice: ");

            fflush(stdin);

            scanf("%c", & rt);

            system("cls");

            break;

        }

    } while (pinTries < 3);

    if (pinTries < 3) {

        do {

            printf("\nCHOOSE FROM THE FOLLOWING \n1.Fast Cash\n2.Withdraw\n3.Deposit\n4.Check Balance\n5.Get Card Back \nEnter your choice:");

            scanf("%d", & userChoice);

            switch (userChoice) {

            case 1:

                printf("\nFast Cash:\n1-->$20.00 \t2-->$40.00\t 3-->$80.00\t4-->$100.00 ");

                scanf("%d", & userChoice);

                if (balance > userChoice) {

                    switch (userChoice) {

                    case 1:

                        balance = balance - 20;

                        break;

                    case 2:

                        balance = balance - 40;

                        break;

                    case 3:

                        balance = balance - 80;

                        break;

                    case 4:

                        balance = balance - 100;

                        break;

                    default:

                        printf("\nInvalid Choice\n");

                    }

                } else {

                    system("cls");

                    printf("\nSorry not enough balance");

                }

                printf("\nYour Balance is: %f\n", balance);

                break;

            case 2:

                printf("\nEnter amount (0 to Cancel) : ");

                scanf("%d", & userChoice);

                if(userChoice == 0)

                    break;

                else if (balance > userChoice) {

                    balance = balance - userChoice;

                    system("cls");

                    printf("\nTake your cash… ");

                } else {

                    system("cls");

                    printf("\nSorry not enough balance");

                }

                printf("\nYour Balance is: %f", balance);

                   printf("\n1.Another Transaction\n 2.Get Card Back: ");

                   scanf("%d",&userChoice);

                                                               if(userChoice == 2)

                                                                              userChoice = 5;

                   break;

                break;

            case 3:

                printf("\nEnter amount to deposit: ");

                scanf("%d", & userChoice);

                system("cls");

                balance = balance + userChoice;

                printf("\nYour final Balance is: %f", balance);

                break;

            case 4:

                printf("\nYour Balance is: %f", balance);

                break;

            case 5:

                printf("\nTake yoyr card.....Goodbye! ");

                break;

            default:

                printf("\nInvalid Choice\n");

            }

        } while (userChoice != 5);

        system("cls");

        printf("\nTHANK FOR USING OUR VIRTUAL BANK SYSTEM GOODBYE");

    } else

        printf("\nSorry you can't continue, contact your bank for assistance!");

    return 0;

}

Output:


Related Solutions

Write a C/C++ program that simulate a menu based binary numbercalculator. This calculate shall have...
Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities:Covert a binary string to corresponding positive integersConvert a positive integer to its binary representationAdd two binary numbers, both numbers are represented as a string of 0s and 1sTo reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the following three functions:int binary_to_decimal(string...
Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program...
Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program to schedule disk in seek optimization.
In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling...
In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling algorithm. It should implement threads for the algorithm plus the main thread using a linked list to represent the list of jobs available to run. Each node will represent a Job with the following information: int ProcessID int time time needed to finish executing The thread representing the scheduler algorithm should continue running until all jobs end. This is simulated using the time variable...
Write source code in C to simulate the contiguous file allocation with the following conditions: •...
Write source code in C to simulate the contiguous file allocation with the following conditions: • Prompt the user to ender the no of files • Enter the name of the file • Enter the Starting block number • Enter no of block occupied by the file i.Condition: No two files must have the same block(if the user enter the same block no present in the previous file prompt the user “Block already in use”) #include<stdio.h> #include<conio.h> struct {    ...
Assignment (C language) We will simulate the status of 8 LEDs that are connected to a...
Assignment (C language) We will simulate the status of 8 LEDs that are connected to a microcontroller. Assume that the state of each LED (ON or OFF) is determined by each of the bits (1 or 0) in an 8-bit register (high-speed memory). Declare a char variable called led_reg and initialize it to 0. Assume that the least-significant bit (lsb) controls LED#0 and the most-significant bit (msb) controls LED#7. In the main function, build and present a menu to the...
C++ Using what you know about inputs and outputs, code a simple ATM interaction. Your ATM...
C++ Using what you know about inputs and outputs, code a simple ATM interaction. Your ATM will start with only $500 to give out, and YOUR balance will be 1000. The amounts the ATM can dispense are $40, $80, $200 and $400. After you've received your disbursement, the console will show the amount you have left in your account, as well as how much the ATM has to dispense (we live in a small, fictional town - no one will...
I need to create a program that will simulate an ATM. The program has to be...
I need to create a program that will simulate an ATM. The program has to be written in JAVA that uses JOptionaPane to pop up the messages. It will need to simulate to get ** balance **withdraw **Deposit **exit the atm ** need to have a method that shows a receipt of everything that was done during the transaction
please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Question: PROJECT 2 – ATM MACHINE For this project you will be building an ATM application...
Question: PROJECT 2 – ATM MACHINE For this project you will be building an ATM application that will allow ... PROJECT 2 – ATM MACHINE For this project you will be building an ATM application that will allow users to log in, deposit, withdraw, and check balance. Set a default beginning balance of $1000. I want all monies formatted to currency. Log in Usernames and passwords need to be stored in parallel arrays. At least three logins available for me....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT