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

  • 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...

  • 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])...

  • 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,...

  • 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...

  • 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...

  • create case 4 do Method 1:copy item by item and skip the item you want to...

    create case 4 do Method 1:copy item by item and skip the item you want to delete after you are done, delete the old file and rename the new one to the old name. #include int main(void) { int counter; int choice; FILE *fp; char item[100]; while(1) { printf("Welcome to my shopping list\n\n"); printf("Main Menu:\n"); printf("1. Add to list\n"); printf("2. Print List\n"); printf("3. Delete List\n"); printf("4. Remove an item from the List\n"); printf("5. Exit\n\n"); scanf("%i", &choice); switch(choice) { case 1:...

  • this is the code you should use from already existing shell i created . Just gothrough...

    this is the code you should use from already existing shell i created . Just gothrough the programand execute that command.and execute in linux. It takes the command from the user and execute. #include<stdio.h>i #include<stdlib.h> #include<string.h> int main() { //cmd1 is the ,hr variable which holds the commands char cmd1[10]; printf("Enter the command without options like ls or date"); scanf("%s",&cmd1); printf("%s\n",cmd1); //system function is used for to run the unix commad, it use system(cmd1); return 0; } #include<stdlib.h> int main()...

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
ADVERTISEMENT