How to create a simple ATM Machine in C programming

Whether you are looking for an ATM Machine code in C++ or in C programming, the concept is the same. Under this walkthrough, we are going to see how to create a simple ATM Machine in the C programming language. C programming is perfect for beginners and hence our choice to create an ATM Machine program. I had initially created an ATM machine using java programming language, applying the same concept used here. It’s essential for you to have some simple basics of C programming before proceeding.

How to create a simple ATM MACHINE using C programming Language

In our program, we are going to apply the 4 basics concept of every ATM MACHINE as shown below:

  1. Withdraw
  2. Deposit
  3. Balance Check
  4. Another transaction functionality for example, “Do you need another transaction? press 1 to proceed, press 2 to exit”. This is to enable multi-transaction in our program, in short, program to be terminated only when the user is satisfied

To accomplish the above concepts, we must use a switch statement, to allow the user to select the required options. SWitch statement in C programming is simple to use.



C PROGRAMMING ATM MACHINE CODE

Following is our C programming ATM code, which is simple to use. In case everything is not clear to you, please feel free to ask any question in the commenting system below.



 

#include <stdio.h>

float balance = 0; // intial balance to be zero for everyone 
int anotherTransaction; 


void transaction(){
  int choice; 
  printf("Enter any option to be served!\n\n");
  printf("1. Withdraw\n"); 
  printf("2. Deposit\n"); 
  printf("3. Balance\n");
  scanf("%d",  &choice); 
  
  switch(choice){
    case 1:
    // first option should be withdraw
    int amountToWidthdraw; 
    printf("Please enter amount to withdraw: "); 
    scanf("%d", &amountToWidthdraw); 
    if(amountToWidthdraw > balance){
      printf("There is no insuffient funds in your account"); 
      // ask them for another transaction
      printf("\n\nDo you want another transaction?\nPress 1 to proceed and 2 to exit\n\n"); 
      scanf("%d", &anotherTransaction); 
      if(anotherTransaction == 1){
        // call our transaction method here
        transaction();
      }
    } else {
      // this means account has something
      // so withdraw amount and update the balance variable 
      balance = balance - amountToWidthdraw; 
      
      printf("You have withdrawn %d and your new balance is %f ", amountToWidthdraw, balance);
      
      // request for another transaction
      printf("\n\nDo you want another transaction?\nPress 1 to proceed and 2 to exit\n\n"); 
      scanf("%d", &anotherTransaction); 
      if(anotherTransaction == 1){
        // call our transaction method here
        transaction();
      }
      
      
    }
    break; 
    
    case 2:
    // DEPOSIT
    
    int amountToDeposit; 
    printf("Please enter amount to deposit: "); 
    scanf("%d", &amountToDeposit); 
    // now that you have deposited something, update the balance variable
    
    balance = amountToDeposit + balance; 
    
    printf("Thank you for depositing, new balance is: %f", balance); 
    
    // request for another transaction
      printf("\n\nDo you want another transaction?\nPress 1 to proceed and 2 to exit\n\n"); 
      scanf("%d", &anotherTransaction); 
      if(anotherTransaction == 1){
        // call our transaction method here
        transaction();
      }
    
    break; 
    
    case 3:
    
    // BALANCE
    printf("Your bank balance is: %f", balance); 
    
    // request for another transaction
      printf("\n\nDo you want another transaction?\nPress 1 to proceed and 2 to exit\n\n"); 
      scanf("%d", &anotherTransaction); 
      if(anotherTransaction == 1){
        // call our transaction method here
        transaction();
      }
    
    break;
  }
  
}



int main(){
  
  // let's try to run our application and see if it's working, please
  
  transaction();
  
  return 0;
}

 

Video on how to create an ATM MACHINE using C Programming



AdBlock Detected!
This site depends on revenue from ad impressions to survive. If you find this site valuable, please consider disabling your ad blocker or pausing adblock for this website.