ATM MACHINE PROTOTYPE using C programming language
//hello everyone my name is Manjunath. G. Dharappanavar
//this is a ATM Machine program in c language
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int atm(int amount);
struct account {
char name[100];
int password;
int amount;
};
struct account p1 = {"Rohan", 1234, 2000};
struct account p2 = {"Chetan", 2023, 4500};
struct account p3 = {"Akash", 2204, 3000};
int main() {
char userName[100];
int userpass;
printf("enter name:");
scanf(" %s", userName);
// force convert to lower case.
for(int i = 0; i<strlen(userName); i++) {
userName[i] = tolower(userName[i]);
p1.name[i] = tolower(p1.name[i]);
p2.name[i] = tolower(p2.name[i]);
p3.name[i] = tolower(p3.name[i]);
}
printf("enter password:");
scanf("%d", &userpass);
if(strcmp(userName, p1.name)==0) {
if(userpass == p1.password) {
printf("welcome %s\n", userName);
atm(p1.amount);
}
}
else if(strcmp(userName, p2.name)==0) {
if(userpass == p2.password) {
printf("welcome %s\n", userName);
atm(p2.amount);
}
}
else if(strcmp(userName, p3.name)==0) {
if(userpass == p3.password) {
printf("welcome %s\n", userName);
atm(p3.amount);
}
}
else {
printf("Invalid Input.");
}
return 0;
}
//ATM Machine program.
int atm(int amount) {
int n;
int withdraw;
int deposit;
while(1) {
printf("enter:\n");
printf("1: Check Balance.\n");
printf("2: Withdraw Cash.\n");
printf("3: Deposit.\n");
printf("4: To exit.\n");
printf(":-");
scanf("%d", &n);
switch(n) {
case 1:
printf("your balance is %d\n ", amount);
break;
case 2:
printf("Withdraw cash.\n");
printf("enter amount:");
scanf("%d", &withdraw);
if(withdraw > amount) {
printf("withdraw exceeds balance.\n");
break;
}
else {
amount = amount - withdraw;
printf("Rs %d deducted. account bal: %d\n ", withdraw, amount);
break;
}
case 3:
printf("Deposit cash:\n");
printf("enter amount:");
scanf("%d", &deposit);
amount = amount + deposit;
printf("Rs %d credited. account bal: %d \n", deposit, amount);
break;
case 4:
printf("Thank you for visiting");
return 0;
default:
printf("Invalid Input.\n");
}
}
}
Comments
Post a Comment