Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C Programming Suppose you’re in charge of this simulation and here is a scena

ID: 3817292 • Letter: I

Question

In C Programming

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 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)

THANK FOR USING OUR VIRTUAL BANK SYSTEM

GOODBYE. . .

Explanation / Answer

program.c -------

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

void virtualBank(double);
int charToNumber(char);

int main()
{
   srand(time(0));
   double balance = ((double)rand() / (double)RAND_MAX) * 1000;
   printf(" Balance - %lf ",balance);
   virtualBank(balance);
   return 0;
}

void virtualBank(double balance)
{
   printf(" Virtual Bank Welcome ");
   int count = 3, i = 0, temp, flag;
   char c;
   double x, bal = balance;
   printf(" Enter PIN : ");
   do
   {
       flag = 1;
       //printf(" Enter Pin : ");
       while((c = getchar()) != ' ')
       {
           temp = charToNumber(c);
           if(temp >= 0 && temp <= 9)
           {
           }
           else
           {
               flag = 0;
               break;
           }
           ++i;
           if(i == 5)
           {
               flag = 0;
               break;
           }
       }
       //printf(" i - %d ",i);
       if(!flag || i != 4)
       {
           count--;
           if(count > 0)
               printf(" Invalid PIN, Re - enter PIN : ");
       }
       else
       {
           break;
       }
   }while(count > 0);
   if(count <= 0)
   {
       printf(" Sorry you can't continue, contact your bank for assistance ");
       return;
   }
   system("clear");
   printf(" Receipt y or Y -> Yes No <- n or N Enter choice : "), scanf("%c", &c);
   system("clear");
   while(1)
   {
       printf(" Choose from the following 1. Fast Cash 2. Withdraw 3. Deposit 4. Check Banlance 5. Get Card Back Enter choice - ");
       scanf("%d", &temp);
       switch(temp)
       {
           case 4:
               system("clear");
               printf(" Your Balance : %lf ",bal);
               break;
           case 2:
               system("clear");
               while(1)
               {
                   printf(" Enter amount(enter 0 to cancel) : "), scanf("%lf", &x);
                   if(x == 0)
                       break;
                   if(x <= bal)
                   {
                       bal -= x;
                       printf(" Take your cash ");
                       break;
                   }
                   else
                   {
                       printf(" Sorry not enough balance ");
                   }
               }
               system("clear");
               printf(" Your balance is : %lf ", bal);
               break;
           case 5:
               printf(" Thank you for using our Virtual Bank System GoodBye.......... ");
               return;
           case 1:
           {
               printf(" 1. $20.00 2 $40.00 3. $80.00 4. $100.00 Enter choice : "), scanf("%d", &i);
               switch(i){
               case 1:
                   if(bal - 20 >= 0)
                       printf(" Take your cash........ "), bal -= 20;
                   else
                       printf(" Sorry not enough balance ");
                   break;
               case 2:
                   if(bal - 40 >= 0)
                       printf(" Take your cash........ "), bal -= 40;
                   else
                       printf(" Sorry not enough balance ");
                   break;
               case 3:
                   if(bal - 80 >= 0)
                       printf(" Take your cash......... "), bal -= 80;
                   else
                       printf(" Sorry not enough balance ");
                   break;
               case 4:
                   if(bal - 100 >= 0)
                       printf(" Take your cash............ "), bal -= 100;
                   else
                       printf(" Sorry not enough balance ");
                   break;
               default:
                   printf(" Invalid option ");}
           }
               break;
           case 3:
               printf(" Enter amount : "), scanf("%lf", &x);
               bal += x;
               system("clear");
               printf(" Your balance is : %lf ", bal);
               break;
           default:
               printf(" Invalid option ");
       }
       printf(" 1. Another Transcation 2. Get Card Back Enter choice : "), scanf("%lf", &flag);
       if(flag == 2)
       {
           printf(" Thank you for using our Virtual Bank System GoodBye............ ");
           return;
       }
   }
   //printf(" Thank you for using our Virtual Bank System GoodBye........... ");
}

int charToNumber(char c)
{
   return (c - '0');
}