Hello all,
can anyone PLEASE help me regarding my problem, I have to write an atm machine program in c and I have to use file processing.
How can I make a file where is stored everything I do on that atm program, like if I entered to check balance, in file should be written balance: 8500, for withdraw: withdraw: 100,balance: 8400, for deposit, deposit: 400, balance 8800.
thank you.
here is the code:
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int pin;
int i;
int almeidPin={1234};
int hadisPin={2345};
int almirPin={3456};
int ahmedPin={4567};
int almaPin={5678};
int lejlaPin={6789};
int selmaPin={7890};
int belmaPin={1010};
int newTry;
int menuOption;
int firstWthd;
double balance = 8500;
double deposit;
int withdraw;
int cont;
int option=0;
printf("*****| WELCOME to Unknown Bank! Thank you for banking |*****\n\n\n");
printf("_________________________| Main Menu |________________________\n");
printf("..............................................................\n\n");
printf("1)Enter Pin #\n");
printf("2)Exit\n\n");
printf("..............................................................\n\n");
scanf("%d", &option);
if (option!=1 && option!=2)
printf("\nInvalid input,try again!\n\n");
if (option==1)
{
system ("cls");
printf("\n Pin Number Verification\n");
printf("-----------------------------------\n\n");
printf("\n__________Enter your pin:__________\n\n");
scanf("%d",&pin);
if (pin==almeidPin || pin==hadisPin || pin==almirPin || pin==ahmedPin
|| pin==almaPin || pin==lejlaPin || pin==selmaPin || pin==belmaPin) goto next;
else
for (i=0;i<3;i++)
{
if(i==2) return 0;
printf("\nWrong pin number! Enter your pin correctly:\n\n");
scanf("%d",&newTry);
if(newTry==almeidPin || newTry==hadisPin || newTry==almirPin || newTry==ahmedPin
|| newTry==almaPin || newTry==lejlaPin || newTry==selmaPin || newTry==belmaPin) goto next;
}
next:
system ("cls");
printf(" Transactions\n");
printf("------------------------------------------\n");
printf("1) Balance\n\n2) Withdraw\n\n3) Deposit\n\n4) Exit\n\n");
printf("------------------------------------------\n");
scanf("%d",&menuOption);
switch(menuOption)
{
case 1:
printf("\n______________Balance iquiry______________\n\n");
printf("Your balance is: %lf KM\n\n",balance);
printf("Press 5 to continue...\n\n");
scanf("%d",&cont);
if (cont=5)
goto next;
break;
case 2:
printf("\n_________________Withdraw_________________\n\n");
printf("Enter amount you want to withdraw:\n\n");
printf("1) 10KM 4) 80KM \n2) 20KM 5) 100KM \n3) 50KM 6) Other \n7) Cancel\n\n");
scanf("%d",&firstWthd);
if (firstWthd==1)
{
balance=balance-10;
printf("\nYour withdraw is: 10 KM");
printf("\n\nYour remaining balance is: %lf KM\n\n",balance);
printf("Press 5 to continue...\n\n");
scanf("%d",&cont);
if (cont=5)
goto next;
}
else if (firstWthd==2)
{
balance=balance-20;
printf("\nYour withdraw is: 20 KM");
printf("\n\nYour remaining balance is: %lf KM\n\n",balance);
printf("Press 5 to continue...\n\n");
scanf("%d",&cont);
if (cont=5)
goto next;
}
else if (firstWthd==3)
{
balance=balance-50;
printf("\nYour withdraw is: 50 KM");
printf("\n\nYour remaining balance is: %lf KM\n\n",balance);
printf("Press 5 to continue...\n\n");
scanf("%d",&cont);
if (cont=5)
goto next;
}
else if (firstWthd==4)
{
balance=balance-80;
printf("\nYour withdraw is: 80 KM");
printf("\n\nYour remaining balance is: %lf KM\n\n",balance);
printf("Press 5 to continue...\n\n");
scanf("%d",&cont);
if (cont=5)
goto next;
}
else if (firstWthd==5)
{
balance=balance-100;
printf("\nYour withdraw is: 100 KM");
printf("\n\nYour remaining balance is: %lf KM\n\n",balance);
printf("Press 5 to continue...\n\n");
scanf("%d",&cont);
if (cont=5)
goto next;
}
else if (firstWthd==7)
{
return 0;
}
else if (firstWthd==6)
printf ("\nEnter amount you want to withdraw:\n\n");
scanf("%d",&withdraw);
if (balance>withdraw && withdraw>0 && withdraw%10==0)
{
balance=balance-withdraw;
printf("\nYour withdraw is: %d KM",withdraw);
printf("\n\nYour remaining balance is: %lf KM\n\n",balance);
printf("Press 5 to continue...\n\n");
scanf("%d",&cont);
if (cont=5)
goto next;
}
else
{
printf("\nYou have to enter rounded number between 0 and %lf to withdraw!\n\n",balance);
system ("pause");
goto next;
}
break;
case 3:
printf("\n_________________Deposit__________________\n\n");
printf("Enter your deposit:\n\n");
scanf("%lf",&deposit);
balance = balance + deposit;
printf("\nYou deposited: %lf KM",deposit);
printf("\n\nYour new balance is: %lf KM\n\n",balance);
printf("Press 5 to continue...\n\n");
scanf("%d",&cont);
if (cont=5)
goto next;
break;
case 4:
printf("\n________________Exit mode_________________\n\n");
break;
default:
printf("\nThat is invalid option!!!\n\n");
system ("pause");
goto next;
break;
}
}
return 0;
}