by David Hamrick

Home
Links

Starting Out
Compiler
Hello World Program
Comments

Variables
Int, Char, Float

Scanf

Projects
ATM project
Maze project
Unit Conversion project




ATM Project

I started the ATM project when i first started programming. It is a simple emulator of the ATM Machine. This is an example of bad programming.

MAIN.CPP

#include <stdio.h>

#include <conio.h>

#include "sysfunc.h"

#include "atmfunc.h"

 

#define KEY1 49

#define KEY2 50

#define KEY3 51

#define KEY4 52

#define KEY5 53

 

 

int main()

{

  int mainsel;

  int pin[5];

 

 

  cls();

 

 

 

  printf("Enter Pin Number\n");

  pin[1] = getch(); 

  pin[2] = getch();                                        

  pin[3] = getch();                                        

  pin[4] = getch();

                                        

 

  if(pin[1] == KEY1 && pin[2] == KEY3 && pin[3] == KEY5 && pin[4] == KEY2)

  {

   

  }

  else

  {

    goto end;

  }

 

 

 

 

  cls();

 

  start:

 

  printf("Enter Selection\n");

 

  printf("1\tDisplay Balance\n");

  printf("2\tDeposit Funds\n");

  printf("3\tTransfer Funds\n");

  printf("4\tWithdraw Funds\n");

  printf("5\tExit\n\n");

 

 

  mainsel = getch();

 

  if(mainsel == KEY1)

  {

    db();

  }

 

  if(mainsel == KEY2)

  {

    df();

  }

 

  if(mainsel == KEY3)

  {

    tf();

  }

 

  if(mainsel == KEY4)

  {

    wf();

  }

 

  if(mainsel == KEY5)

  {

    goto end;

  }

 

  goto start;

 

 

 

  end:

  cls();

}


ATMFUNC.CPP

#include <stdio.h>

#include "sysfunc.h"

 

int balance = 254;

int allow = 200;

 

 

 

int db()

{

  cls();

 

  printf("\nCurrent Account Balance: %d\n\n\n",balance);

 

 

 

  return 0;

}

 

int df()

{

  int add;

 

  cls();

 

 

  printf("Enter Ammount to Add to Account\n");

  scanf("%d", &add);

 

  balance = balance + add;

  cls();

 

  printf("\n\nNew Account Balance: %d\n\n\n", balance);

 

 

 

  return 0;

}

 

 

int tf()

{

  cls();

 

  printf("Sorry, Service Unavailable at the Moment\n\n\n");

 

  return 0;

}

 

int wf()

{

  int with;

 

 

 

  cls();

 

  printf("Enter Ammount to Withdraw\n");

  scanf("%d", &with);

 

  cls();

 

  if( with > 201 )

  {

    printf("Sorry, Can only take out $200\n\n");

  }

 

  if( with > balance )

  {

    printf("Sorry, balance is to low\n\n");

  }

 

  if( with > allow )

  {

    printf("Sorry, Daily Allowance is only $200. Please come back tomarow\n\n");

  }

 

 

  if(with < 201 && with < balance && with <= allow)

  {

    balance = balance - with;

 

    printf("New Account Balance: %d\n\n",balance);

 

    allow = allow - with;

 

  }

 

 

  return 0;

}

ATMFUNC.H

//ATM Functions

int db(); //Display Balance

int df(); //Deposit Funds

int tf(); //Transfer Funds

int wf(); //Withdraw Funds
 

SYSFUNC.CPP

#include <stdlib.h>

void cls()

{

  system("cls");

}

 

void EXIT()

{

  system("exit");

}



SYSFUNC.H

void cls(); //clears the screen

void EXIT(); //exits the program and prompt


 

 

 


 

     

 

Hosted by www.Geocities.ws

1