hello friends,
may anyone help me with a code in c for the mechanism of using an atm machine,
conditions
1.acc balance starts at zero
2.do not use global variables
3.loop the main menu after every transaction until user presses exit
4.after every transaction user returns to the main menu.
menu
a. deposit
b. withdraw
c. balance inquiry
d. fast cash - a-100
b-200
c-500
d-1000
and exit

Recommended Answers

All 12 Replies

you want ready made code !!! I dont think folks here will do that for you :)

by the way some hints...
1.for looping..you have to write entire menu in a do-while loop
2.you case you an array to store what all denomination of note you want to dispense...take help of modulo operator to decide how many notes already dispensed and how much of what denomination you need to give...
since no global is allowed so give lot of time in design and decide function parameters...

hope it helps

I'm totaly agreed with rajeevpareek, don't you think it would be beneficial for you to develop your own codes. grow up bro !!!!!!!

i am a junior programmer so dont be surprised by the simplicity of the code i am using
i have managed to write the code for the atm machine but i dont know why one case switch (case3 abd case 4),the complier has showed no error
please help
<as i said i'm a junior programmer>

here is the code

#include<stdio.h>
#include<conio.h>
main()
{
  int choice,choice2;
  float withd, depo,bal;
  bal=0;
  withd=0;
  depo=0;
  clrscr();
  do
  {

  clrscr();
  printf("**********Da.Bank***********\n");
  printf("*****************************\n\n");
  printf("1. Deposit\n");
  printf("2. Withdraw \n");
  printf("3. Balance inquiry \n");
  printf("4. Fast cash \n");
  printf("5. Exit\n");
  printf("\nenter choice:");
  scanf("%d",&choice);
  switch(choice)
  {
    case 1:  printf("\n\n\nDEPOSIT MENU");
	     printf("\n***************");
	     printf("\nplease enter deposit amount:");
	     scanf(" %f",&depo);
	     if(depo > 0 )
	      {
		bal = bal + depo;
		printf("\nyou have deposited %.2f",depo);
		printf("\nyour new acount balance is %.2f\n\npress any key to continue:",bal);
	      }
	     else
	      {
		 printf("\nerror:you can not deposit less than 0" );
		 printf("\n\n\npress any key to continue:");
	      }
	     break;

    case 2: printf("\nWITHDRAW MENU");
	     printf("\n*****************************");
	     printf("\nyour current ballance is %.2f",bal);
	     printf("\nplease enter withdraw amount:");
	     scanf(" %f",&withd);
	     if(withd <= bal && withd >= 0)
		{
		  bal = bal - withd;
		  printf("\nyou have withdrawn %.2f \nyour curent ballance is %d",withd,bal);
		 }
	      else
	       {
		   printf("\nerror: you have insuficient");
	       }

	      printf("\npress any key to continue:");
	      break;

    case 3:  printf("\nBALANCE INQUIRY MENU");
    	     printf("\nyour account balance is %.2f",bal);
	     printf("\npress any key to continue:");
	     break;

    case 4: printf("\nFAST CASH MENU");
	    printf("\n*****************************");
	    printf("\nFast cash options\n1. 100\n2. 200\n3. 500\n4. 1000");
	    printf("\nenter choice:");
	    scanf("%d",&choice2);
	       switch(choice2)
		 { case 1: if(bal > 100)
			    { bal = bal - 100;
			      withd = 100;
			      printf("\nyou have withdrawn %.2f\n your curent balance is .%2f",withd,bal);
			    }
			    else
			     {
			       printf("\ninsuficient funds for this transaction");
			      }
			    printf("\npress any key to continue:");
			    break;

		   case 2: if(bal > 200)
			     { bal= bal - 200;
			       withd=200;
			       printf("\nyou have withdrawn %.2f\n your curent balance is .%2f",withd,bal);
			      }
			      else
			      {
			       printf("\ninsuficient funds for this transaction");
			      }
			    printf("\npress any key to continue:");
			    break;

		   case 3: if(bal > 500)
			     { bal = bal - 500;
			       withd = 500;
			       printf("\nyou have withdrawn %.2f\n your curent balance is .%2f",withd,bal);
			     }
			     else
			     {
			       printf("\ninsuficient funds for this transaction");
			     }
			     printf("press any key to continue:");
			    break;

		   case 4: if(bal > 1000)
			     { bal = bal - 1000;
			       withd = 1000;
			       printf("you have withdrawn %.2f\n your curent balance is .%2f",withd,bal);
			     }
			     else
			     {
			     printf("insuficient funds for this transaction");
			     }
			     printf("press any key to continue:");
			   break;


		 }

	      break;

    case 5: printf("thank you for using this ATM, gudbye");
	    break;

    default: printf("error, please sellect from the give options");
	    break;
   }

  }while(choice != 5);

  getch();
}

i am a junior programmer so dont be surprised by the simplicity of the code i am using
i have managed to write the code for the atm machine but i dont know why one case switch (case3 abd case 4),the complier has showed no error
please help
<as i said i'm a junior programmer>

here is the code

#include<stdio.h>
#include<conio.h>
main()
{
  int choice,choice2;
  float withd, depo,bal;
  bal=0;
  withd=0;
  depo=0;
  clrscr();
  do
  {

  clrscr();
  printf("**********Da.Bank***********\n");
  printf("*****************************\n\n");
  printf("1. Deposit\n");
  printf("2. Withdraw \n");
  printf("3. Balance inquiry \n");
  printf("4. Fast cash \n");
  printf("5. Exit\n");
  printf("\nenter choice:");
  scanf("%d",&choice);
  switch(choice)
  {
    case 1:  printf("\n\n\nDEPOSIT MENU");
	     printf("\n***************");
	     printf("\nplease enter deposit amount:");
	     scanf(" %f",&depo);
	     if(depo > 0 )
	      {
		bal = bal + depo;
		printf("\nyou have deposited %.2f",depo);
		printf("\nyour new acount balance is %.2f\n\npress any key to continue:",bal);
	      }
	     else
	      {
		 printf("\nerror:you can not deposit less than 0" );
		 printf("\n\n\npress any key to continue:");
	      }
	     break;

    case 2: printf("\nWITHDRAW MENU");
	     printf("\n*****************************");
	     printf("\nyour current ballance is %.2f",bal);
	     printf("\nplease enter withdraw amount:");
	     scanf(" %f",&withd);
	     if(withd <= bal && withd >= 0)
		{
		  bal = bal - withd;
		  printf("\nyou have withdrawn %.2f \nyour curent ballance is %d",withd,bal);
		 }
	      else
	       {
		   printf("\nerror: you have insuficient");
	       }

	      printf("\npress any key to continue:");
	      break;

    case 3:  printf("\nBALANCE INQUIRY MENU");
    	     printf("\nyour account balance is %.2f",bal);
	     printf("\npress any key to continue:");
	     break;

    case 4: printf("\nFAST CASH MENU");
	    printf("\n*****************************");
	    printf("\nFast cash options\n1. 100\n2. 200\n3. 500\n4. 1000");
	    printf("\nenter choice:");
	    scanf("%d",&choice2);
	       switch(choice2)
		 { case 1: if(bal > 100)
			    { bal = bal - 100;
			      withd = 100;
			      printf("\nyou have withdrawn %.2f\n your curent balance is .%2f",withd,bal);
			    }
			    else
			     {
			       printf("\ninsuficient funds for this transaction");
			      }
			    printf("\npress any key to continue:");
			    break;

		   case 2: if(bal > 200)
			     { bal= bal - 200;
			       withd=200;
			       printf("\nyou have withdrawn %.2f\n your curent balance is .%2f",withd,bal);
			      }
			      else
			      {
			       printf("\ninsuficient funds for this transaction");
			      }
			    printf("\npress any key to continue:");
			    break;

		   case 3: if(bal > 500)
			     { bal = bal - 500;
			       withd = 500;
			       printf("\nyou have withdrawn %.2f\n your curent balance is .%2f",withd,bal);
			     }
			     else
			     {
			       printf("\ninsuficient funds for this transaction");
			     }
			     printf("press any key to continue:");
			    break;

		   case 4: if(bal > 1000)
			     { bal = bal - 1000;
			       withd = 1000;
			       printf("you have withdrawn %.2f\n your curent balance is .%2f",withd,bal);
			     }
			     else
			     {
			     printf("insuficient funds for this transaction");
			     }
			     printf("press any key to continue:");
			   break;


		 }

	      break;

    case 5: printf("thank you for using this ATM, gudbye");
	    break;

    default: printf("error, please sellect from the give options");
	    break;
   }

  }while(choice != 5);

  getch();
}

i am a junior programmer so dont be surprised by the simplicity of the code i am using
i have managed to write the code for the atm machine but i dont know why one case switch (case3 abd case 4),the complier has showed no error
please help
<as i said i'm a junior programmer>

i am a junior programmer so dont be surprised by the simplicity of the code i am using
i have managed to write the code for the atm machine but i dont know why one case switch (case3 abd case 4),the complier has showed no error
please help
<as i said i'm a junior programmer>

and obviously the head of the Department of Redundancy Department, too...

As for the question, what kind of error would you like it to have? You have to program the one case statement :icon_rolleyes: with an error the compiler can't handle to get a compiler error.

Please proofread your posts before you submit them to be sure you have made accurate and understandable statements. If not, feel free to edit your post before submitting, or click the EDIT POST button after submitting to clean up any questionable information.

I'm not sure of your problem, but the only compiler errors I see are the clrscr() (not really a "c" function. That said in testing I found errors after Withdraw and Fast Cash. After Withdraw you display a balance of 0 (zero). After Fast Cash you display a balance of .4845.000000. 4845.00 is displayed after Balance Inquiry.
The first problem is calling bal %d in the printf even though it is a float. Change %d to %.2f and that fixes that. The second is similar, bal is .%2f should be %.2f.

Those changes and all seems to be OK. If you want to have a clear screen that works in all compilers you will have to code it.

thanks that is the solution i needed my friend, you arr a life savor

hello friends,

i had problem in my asignment C programming.
“There are two bank accounts: current and savings. First, ask the initial balances of the bank accounts; reject negative balances. Then ask for the transactions; options are deposit, withdrawal and transfer. Then ask for the account; options are current and savings. Then ask for the amount; reject transactions that overdraw an account. At the end, print the balances of both accounts

can u make a flowchart of this simple atm?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.