Question

Create a functional ATM using the code base given in the example. You must use the...

Create a functional ATM using the code base given in the example. You must use the routines provided in the code base example.

Failure to follow the directions will result in an 'F'

the example is down below!

/*
 * @desc: Simple ATM machine
 * @duedate: 23-April-2019
 * 
 *
 *
 */
 
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>

char menu();
char transaction_menu();

/* Verifies the Pin Entered match the PIN on record */
int validatePin(int);

/* Verifies the funds requested are available to perfrom the transaction 
 * 0 - Ok to perform transaction, 1 -  funds not available
 */
int verify(double, double);

/* Each of the following routines should update a specific balance
 * after the transaction has been completed
 */
double chk_deposit();
double chk_withdraw();
double sav_deposit();
double sav_withdraw();
void transfer(double, double);

int validatePin(int pin){
    int entered_pin =0;
    printf("Enter PIN ");
    scanf("%d", &entered_pin);
    return entered_pin != pin;
    /*
    if (entered_pin != pin){
        return 1;
    }
    return 0;
    */
}

char transaction_menu(){
    char c;
    printf("S - SAVING\t\tC - CHECKING\n");
    printf("Enter Choice:");
    scanf(" %c", &c);
    if (c == 'S' || c = 's'){
        return 'S'
    }
    else{
        return 'C';
    }
}

char menu(){
    char c;
    printf("----------------------- MENU --------------------\n");
    printf("C - CHECK BALANCE\t\tD - DEPOIST\n");
    printf("T - TRANSFER\t\t\tW - WITHDRAW\n");
    printf("Y - ANOTHER TRANSACTION\t\tE - END\n");
    
    printf("Enter Choice:");
    scanf(" %c", &c);
    return c;
}


int main(){
    
    char choice, t_choice;
    
    srand(time(NULL));
    int pin = rand() % 9999;
    int acct_num = rand() % 99999;
    double chk_acct_bal = rand() % 99999;
    double sav_acct_bal = rand() % 99999;
    
    printf("PIN: %d\n", pin);
    printf("Account#: %d\n", acct_num);
    printf("Checking Balance: %.2f\n", chk_acct_bal);
    printf("Saving Balance: %.2f\n", sav_acct_bal);
    if ( validatePin(pin) == 1){
         printf("Oops you messed up....");
        return 1;
    }
    
    while(choice != 'E'){
        choice = menu();
        printf("Choice: %c\n", choice);
        
        if (choice == 'E'){
            printf("Have a nice day, bye.");
            return 0;
        }
        
        if (choice == 'D' || choice == 'W'){
            t_choice = transaction_menu();
            printf("Transaction Choice: %c\n", t_choice); 
        }
        
        if (choice == 'T'){
            printf("Transfer: %c\n", choice); 
        }

    }

    
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

/*
* @desc: Simple ATM machine
* @duedate: 23-April-2019
*
*
*
*/

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

char menu();
char transaction_menu();

/* Verifies the Pin Entered match the PIN on record */
int validatePin(int);

/* Verifies the funds requested are available to perfrom the transaction
* 0 - Ok to perform transaction, 1 - funds not available
*/
int verify(double, double);

/* Each of the following routines should update a specific balance
* after the transaction has been completed
*/
double chk_deposit();
double chk_withdraw();
double sav_deposit();
double sav_withdraw();
void transfer(double, double);

int validatePin(int pin){
int entered_pin =0;
printf("Enter PIN ");
scanf("%d", &entered_pin);
return entered_pin != pin;
/*
if (entered_pin != pin){
return 1;
}
return 0;
*/
}

char transaction_menu(){
char c;
printf("S - SAVING\t\tC - CHECKING\n");
printf("Enter Choice:");
scanf(" %c",&c);
if (c == 'S' || c == 's'){
return 'S';
}
else{
return 'C';
}
}

char menu(){
char c;
printf("----------------------- MENU --------------------\n");
printf("C - CHECK BALANCE\t\tD - DEPOIST\n");
printf("T - TRANSFER\t\t\tW - WITHDRAW\n");
printf("Y - ANOTHER TRANSACTION\t\tE - END\n");
  
printf("Enter Choice:");
scanf(" %c", &c);
return c;
}


int main(){
  
char choice, t_choice;
  
srand(time(NULL));
int pin = rand() % 9999;
int acct_num = rand() % 99999;
double chk_acct_bal = rand() % 99999;
double sav_acct_bal = rand() % 99999;
  
printf("PIN: %d\n", pin);
printf("Account#: %d\n", acct_num);
printf("Checking Balance: %.2f\n", chk_acct_bal);
printf("Saving Balance: %.2f\n", sav_acct_bal);
if ( validatePin(pin) == 1){
printf("Oops you messed up....");
return 1;
}
  
while(choice != 'E'){
choice = menu();
printf("Choice: %c\n", choice);
if(choice=='C' || choice=='c')
{
   t_choice = transaction_menu();
   if(t_choice=='S')
   {
   printf("Your balance is :%.2lf\n",sav_acct_bal);  
           }
           else if(t_choice=='C')
           {
           printf("Your balance is :%.2lf\n",chk_acct_bal);      
           }
  
       }
if (choice == 'E'){
printf("Have a nice day, bye.");
return 0;
}
  
if (choice == 'D' || choice == 'W'){
   double amt;
   if(choice=='D' || choice=='d')
   {
   t_choice = transaction_menu();
printf("Transaction Choice: %c\n", t_choice);
           printf("Enter Amount to Deposit :");
           scanf("%lf",&amt);
           if(t_choice=='S')
           {
               sav_acct_bal+=amt;
           }
           else if(t_choice=='C')
           {
               chk_acct_bal+=amt;
           }
           printf("You have successfully Deposited :%.2lf\n",amt);  
           }
           else if(choice=='W' || choice=='w')
           {
           t_choice = transaction_menu();
printf("Transaction Choice: %c\n", t_choice);
           printf("Enter Amount to Withdraw :");
           scanf("%lf",&amt);
           if(t_choice=='S')
           {
               if(sav_acct_bal-amt>=0)
               {
               sav_acct_bal-=amt;  
           printf("You have successfully Withdrawn :%.2lf\n",amt);  
               }
               else
               {
               printf("** Insufficient Balance **\n");  
               }
              
           }
           else if(t_choice=='C')
           {
               if(chk_acct_bal-amt>=0)
               {
               chk_acct_bal-=amt;  
               printf("You have successfully Withdrawn :%.2lf\n",amt);  
               }
               else
               {
               printf("** Insufficient Balance **\n");  
               }
           }
              
           }
  
}
  
if (choice == 'T'){
   double amt;
   int num;
printf("Transfer: %c\n", choice);
printf("1.Savings Account to Checking Account\n");
printf("2.Checking Account to Savings Account\n");
scanf("%d",&num);
if(num==1)
{
   printf("Enter Amount to Transfer:$");
   scanf("%lf",&amt);
   if(sav_acct_bal-amt<0)
           {
               printf("Insufficient Balance\n");
           }
           else
           {
               sav_acct_bal-=amt;
               chk_acct_bal+=amt;
               printf("You have successfully Transferred :%.2lf\n",amt);
           }
           }
           else if(num==2)
           {
               printf("Enter Amount to Transfer:$");
   scanf("%lf",&amt);
   if(chk_acct_bal-amt<0)
           {
               printf("Insufficient Balance\n");
           }
           else
           {
               chk_acct_bal-=amt;
               sav_acct_bal+=amt;
               printf("You have successfully Transferred :%.2lf\n",amt);
           }  
           }
          
  
}

}

  
}

_______________________________________

Output:

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Create a functional ATM using the code base given in the example. You must use the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x)...

    #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x) = x*x*x\n"); printf ("c: c(x) = x^2 + 2*x + 7\n"); printf ("q: quit\n"); } void a(float x) { float v = x*x; printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v); } // end function a void b(float x) { float v = x*x*x; printf (" a(%.2f) = %.2f^3 = %.2f\n", x, x, v); } // end function b void c(float x)...

  • #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here....

    #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } }    return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...

  • Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the O...

    Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){    char str[1000], ch;    int i, frequency = 0;    clock_t t; struct timespec ts, ts2;       printf("Enter a string: ");    gets(str);    int len = strlen(str);    printf("Enter a character...

  • NEED CODE HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD. COMPARING TWO LETTERS AND CALLING A...

    NEED CODE HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD. COMPARING TWO LETTERS AND CALLING A FUNCTION.   Problem are explained in bold #include <stdio.h> #include <string.h> #include <stdlib.h> #define pi 3.1415 void Area (double n); void VolSphere (double n); void Circumference (double n); void AllCalc (); // i dont know if the declaration of the function is correct AllCalc = AllCalculations //function main begins program execution int main (void) { puts("-Calculating Circle Circumference, Circle Area or Sphere Volume-\n"); void (*f[4])...

  • Create another program that will prompt a user for input file. The user will choose from...

    Create another program that will prompt a user for input file. The user will choose from 4 choices: 1. Display all positive balance accounts. 2. Display all negative balance accounts. 3. Display all zero balance accounts. 4. End program. C PROGRAMMING my code so far #include<stdlib.h> #include<stdio.h> int main(void) { int request; int account; FILE *rptr; char name[20]; double balance; FILE *wptr;    int accountNumber;    if((wptr = fopen("clients.dat","w")) == NULL) { puts("File could not be opened"); } else {...

  • PROGRAMING IN C. PLEASE HELP FIX MY CODE TO FIT THE FOLLOWING CRITERIA: 1.)Read your stocks...

    PROGRAMING IN C. PLEASE HELP FIX MY CODE TO FIT THE FOLLOWING CRITERIA: 1.)Read your stocks from your mystocks.txt file. You can use this information for the simulator. 2.)The stock price simulator will return the current price of the stock. The current prices is the prices of the requested ticker + a random number. 3.)We will assume that the stock price remains constant after the price check till your trade gets executed. Therefore, a buy or a sell order placed...

  • Using the code below, Complete the C program main.c to stop execution if the user attempts...

    Using the code below, Complete the C program main.c to stop execution if the user attempts a divide by 0. #include <stdio.h> int main() { float a, b; printf("Input two integers to divide the first by the second\n"); scanf("%f%f", &a, &b); printf("%f/%f = %.2f\n", a, b, a/b);    return 0; }

  • Using C programming Using the supplied example code as a starting point, add 3 more conversions...

    Using C programming Using the supplied example code as a starting point, add 3 more conversions using strtod(). Make sure you change the output conversion for type double. Use the same input strings and base codes as the strtol() function example but notice how the numbers are now represented. Manipulate the width and precision as needed for a good presentation.   Supplied code: #include <stdio.h> #include <string.h> int main(void) { long num; char* ptr; num = strtol("12345 Decimal Constant: ", &ptr,...

  • I need to modify below code to have output like: Example: RBGY [ You have 1...

    I need to modify below code to have output like: Example: RBGY [ You have 1 white flag and you have 1 red flag] Example: CCGG [ You have 0 white flag and you have 1 red flag] ================================== #include <stdio.h> #include <string.h> #include <time.h> #include <stdlib.h> #define SIZE_STRING 4 #define SIZE_STRING_LONG 15 int main(int argc, char *argv[]){ if(argc != 2) { printf("Usage: ./main <scComputer>"); exit(0); } char szUser[SIZE_STRING_LONG]; char *szComputer = argv[1]; int counter=0; int colour=0; int position=0; char...

  • Do you have a flowgorithim flow chart for this code? #include <stdio.h> int main() { int num,i=0,sum=0; float aver...

    Do you have a flowgorithim flow chart for this code? #include <stdio.h> int main() { int num,i=0,sum=0; float average; int customerNumbers[num]; int customerSales[num]; printf("How many customers do you want to track?\n"); scanf("%d",&num); while(i<num) { printf("Enter the customer number. "); scanf("%d",&customerNumbers[i]); printf("Enter the sales for the customer "); scanf("%d",&customerSales[i]); i++; } printf("Sales for the Customer"); printf("\nCustomer Customer"); printf("\nNumber Sales"); for(i=0;i<num;i++) { printf("\n %d \t %d",customerNumbers[i], customerSales[i]); sum=sum+customerSales[i]; } average=(int)sum/num; printf("\n Total sales are $%d",sum); printf("\n Average sales are $%.2f",average); printf("\n --------------------------------------------");...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT