Thread: atm file processing

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    1

    Question atm file processing

    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;
    
    
    }
    Last edited by mezemon; 06-03-2012 at 04:44 AM. Reason: code

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I added [code][/code] tags, so people can read your code - you should learn to use them

    Now the next things you should address are
    1. indentation, which is pretty poor; see here -> SourceForge.net: Indentation - cpwiki

    2. 'goto' abuse. Change it into a while loop.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Code:
    if (pin==almeidPin || pin==hadisPin || pin==almirPin || pin==ahmedPin
        || pin==almaPin || pin==lejlaPin || pin==selmaPin || pin==belmaPin
    You should be using a do-while so you don't have to use this twice. Also, it would help to make an array of PINs and a separate function, in case you ever wanted to add more:

    Code:
    /* you need to have these */
    int PINs[] = {almeidPen, hadisPin, ....};
    int numPINs = sizeof(PINs) / sizeof(PINs[0]);
    
    /* put this when you're trying to get input */
    do {
        scanf("%d", &pin);
    } while (!valid_PIN(pin, PINs, numPINs));
    
    /* and then, check with this function */
    bool valid_PIN (int pin, int *array, int size)
    {
        /* lol, write it yourself */
    }
    These kinds of changes should be applied to the entirety of your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File processing: How to read a part of a text file?
    By HardOverdrive in forum C Programming
    Replies: 4
    Last Post: 12-05-2011, 12:33 PM
  2. file processing help!!!
    By jamaican1231 in forum C Programming
    Replies: 5
    Last Post: 04-14-2010, 05:44 PM
  3. help:File Processing
    By yacht2009 in forum C Programming
    Replies: 4
    Last Post: 12-20-2008, 01:35 PM
  4. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  5. File processing
    By Nutshell in forum C Programming
    Replies: 2
    Last Post: 01-28-2002, 03:10 AM