TASK-
ATM Machine
Develop a C-Code with full use of functions for the implementation of ATM machine with the following features:
- Have a name of your bank. Make an account of a dummy client with an initial amount of Rs.250,000 and a 4 digit PIN (5678).
- Your code should first of all say Welcome to the client.
- Your code then should ask the client to enter the 4-digit PIN. Check the PIN. If it is incorrect, ask the client again to re-enter the PIN. Allow the client to enter the PIN for maximum three times only. For 3rd incorrect entry, display the message “Your card is captured. Please contact the Bank Manager”, and the program should be terminated.
- If correct PIN is entered (within maximum three attempts), your code should display the following main menu.
- First function would be for pin check!!
- Balance Enquiry (function 2)
- Cash Withdrawal (function 3)
- Cash Deposit (function 4)
- Change PIN (function 5)
- Exit
For Further Detail about the task click here: 👉👉 ATM MACHINE
STEPS:
- We will make separate function for each requirement
- we will use WHILE loop to repeat procedures where required
- we will not use function for exit() because it can be done more easily
- NOTE: These logics are used by us you should try your own but you can get help form the code below!!
CODE:
#include<stdio.h>
#include<stdlib.h>
void pass(); // pin code to login in account
int menu(); // Menu Function to print menu (1)
int balance(); // function to be used for menu option (1) {balance checking}
int cash_withdraw(); // function for menu option (2) {cash withdrawal}
int cash_deposite();// function for menu option (3) {cash deposite}
int pin_change(); // function for menu option (4) {pin chnaging}
// intial amount fixed as per requirement
int pin=5678,intial_amount=250000;
int main(){
//Validity check
printf("\t\t PIEAS BANK\n"); // you can use any name as per choice
printf("\t\t **WELCOME**\n");
pass();
//Main Menu
int ext=0,opt;
char opt2;
while (ext!=1) // loop used to repeat till user press option (5) of menu{exit}
{
opt=menu(); // first function called {menu}
switch(opt)
{
//balance enquiry
case 1:
ext=balance(); // second function called {balance}
break;
// cash withdraw
case 2:
ext=cash_withdraw(); //third function called {cash withdraw}
break;
//CASH DEPOSITE
case 3:
ext=cash_deposite(); // fourth function called {cash deposite}
break;
//Pin change
case 4:
ext=pin_change(); //fifth function called {pin change}
break;
//Exit
case 5:
printf("Thanks, Allah Hafiz, Please Take Your Card");
exit(0);
}
}
getchar();
return 0;
}
//Validity check
void pass()
//as per requirement user has just three tries to enter correct pin!!! after third try card would be captured
{
int entered_pin,count=1;
while (entered_pin!=pin)
{
printf("\nEnter your Pin\n");
scanf("%d",&entered_pin);
if (entered_pin!=pin && count!=3)
printf("\nInvalid try again!\n");
if (count==3 && entered_pin!=pin )
{
printf("Your card is captured. Please contact the Bank Manager");
exit(0);
}
count++;
}
}
int menu()
// menu function!! just printing and getting option
{
int opt;
printf("\t\tPlease select the option\n");
printf("1) Balance Enquiry\n2) Cash Withdrawal\n3) Cash Deposit\n4) Change PIN\n5) Exit\n");
scanf("%d",&opt);
return opt;
}
//balance enquiry
int balance()
{
//this function just has to show current balance
int ext=0;
char s;
printf("Your current balance is %d\n",intial_amount);
printf("Press A to return to main menu or enter B to Exit\n");
scanf("%s",&s);
if (s=='A'||s=='a')
ext=0;
else if(s=='B'||s=='b')
{
printf("\nTHANKYOU FOR USING OUR SERVIES");
ext=1;
}
return ext;
}
//cash withdraw
int cash_withdraw()
{
//cash withdraw the amount a user want to withdraw as per requirement we have to repeat till user want to withdraw
int ext2=0,amount,amount2=25000,ext=0;
char opt2,s;
while (ext2!=2){ // here we have used while loop to repeat till user want
printf("Enter an amount \n");
scanf("%d",&amount);
if (amount>intial_amount)
{
printf("you don't have enough money\n\n");
break;
}
else if (amount>amount2 ) // user can't with draw more than a fixed amount
{
printf("Entered amount is greater than 25000 Try again!!!\n");
continue;
}
else if (amount%500!=0) // and withdrawal amount should be multiple of 500!!!
{
printf("Entered amount is not a multiple of 500 Try again!!!\n");
continue;
}
else
{
intial_amount=intial_amount-amount; //as per logic withdrawal amount should be subtracted from total
printf("Please take your amount %d\n",amount);
printf("Your current balance = %d\n",intial_amount);
printf("Do you want more Withdrawal Transaction? Press Y for Yes or N for No\n");
scanf("%s",&opt2);// used to give choice to user either he/she want to withdraw more or not
if (opt2=='Y'||opt2=='y')
continue;
else if (opt2=='N'||opt2=='n')
break;
}
}
//finally asking either user want to end using service or want any other option to be used
printf("Press A to return to main menu or enter B to Exit\n");
scanf("%s",&s);
if (s=='A'||s=='a')
ext=0;
else if(s=='B'||s=='b')
{
printf("\nTHANKYOU FOR USING OUR SERVIES");
ext=1;
}
return ext;
}
//Cash deposite
int cash_deposite()
{
// function for cash deposite
int ext3,amount3,amount4=90000,ext;
char opt2,s;
while (ext3!=3)
{
printf("Enter an amount\n");
scanf("%d",&amount3);
if (amount3>amount4)// cash can't be deposited more than a fixed amount
{
printf("Entered amount is greater then %d Try again!!!\n",amount4);
continue;
}
else if (amount3%500!=0) // depositing cash should be multiples of 500
{
printf("Entered amount should be multiple of 500 Try again!!!\n");
continue;
}
else
{ intial_amount=intial_amount+amount3; //as per logic deposited amount should be added to total printf("Your amount has been deposited\n"); printf("Your current balance = %d\n",intial_amount); printf("Do you want more Deposite Transaction? Press Y for Yes or N for No\n"); scanf("%s",&opt2);// used to give choice to user either he/she want to deposite more or not if (opt2=='Y'||opt2=='y') { continue; } else if (opt2=='N'||opt2=='n') break; } } //finally asking either user want to end using service or want any other option to be used printf("Press A to return to main menu or enter B to Exit\n"); scanf("%s",&s); if (s=='A'||s=='a') ext=0; else if(s=='B'||s=='b') { printf("\nTHANKYOU FOR USING OUR SERVIES"); ext=1; } return ext; } int pin_change() { //we are making an efficient atm hence we are giving option for pin changing int ext,ext4=0,ext5=0,new_pin1,new_pin2,_new_pin3,old_pin; char s; while (ext4=4){ printf("Enter old pin\n"); scanf("%d",&old_pin); // this is done to ensure that user is real owner of occount if (old_pin!=pin) { printf("Invalid try again\n"); continue; } else { printf("Enter new pin\n"); scanf("%d",&new_pin1); // 1st time new pin entered while (ext5=5){ printf("Enter new pin again \n"); scanf("%d",&new_pin2); // get second time till 1st and 2nd pin get same if (new_pin2!=new_pin1){ printf("Error!!! Enter second pin again\n"); continue;} else{ pin=new_pin1;//finally change the pin //note: if you want to change pin permanently you should learn file handling printf("Pin changed successfully\n"); break;} } } break; } //finally asking either user want to end using service or want any other option to be used printf("Press A to return to main menu or enter B to Exit\n"); scanf("%s",&s); if (s=='A'||s=='a') ext=0; else if(s=='B'||s=='b') { printf("\nTHANKYOU FOR USING OUR SERVIES"); ext=1;} return ext; }
EXPECTED Output (With Cases):
CASE 1:
Validity
Case 1: When all Tries are fail!
Thanks sir
ReplyDelete