c++ program for ATM machine

This is a discussion on c++ program for ATM machine within the C++ Programming forums, part of the General Programming Boards category; Write a program that simulates an ATM machine. Assume an initial balance of 10000. A user may withdraw, deposit, or ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    1

    c++ program for ATM machine

    Write a program that simulates an ATM machine.

    Assume an initial balance of 10000. A user may withdraw, deposit, or inquire as many times as he desires. The program will only end when the user chooses to quit the program, otherwise the program should loop and prompt the users for actions.
    For security, include an authentication routine that will prompt the user to enter a password. The user is only allowed three attempts to enter the correct password. After the third attempt the program should terminate.

    Code:
    /*
    ***Automated Teller Machine with authentication routine***
    by MikhaeL Franko T. Mogol
    */
    #include<iostream.h>
    
    
    int main()
    
    {
    	
    	int password;
    
    for (int i=0;i<3;i++)
    
    {cout <<"enter password:\n";
    	cin>>password;
    	
    	if (password==123456)
    	{cout<<"korek!!!\n";
    
    	double balance = 10000;
    	double withdraw, deposit;
    	int option;
    cout<<"\n";
    cout<<"           ***MOGOL***\n";
    	cout<<"*** Automated Teller Machine***"<<endl;
    	cout<<"Choose a Transaction:\n";
    	cout<<"\n";
    	cout<<"[1] Inquire Balance \n"
    		<<"[2] Withdraw \n"
    		<<"[3] Deposit \n"
    		<<"[4] Quit \n"
    		<<"\n"
    		<<"Enter Option:";
    	cin>>option;
    
    	switch(option)
    	{
    	case 1:
    		cout<<"\n[[[BALANCE INQUIRY]]]\n";
    		cout.setf(ios::fixed);
    		cout.setf(ios::showpoint);
    		cout.precision(2);
    		cout<<"\n Your current balance is $"<<balance<<endl;
    		break;
    	case 2:
    		cout<<"\n[[[WITHDRAW]]]\n";
    		cout<<"Enter amount: $";
    		cin>>withdraw;
    		
    		balance = balance - withdraw;
    		
    		cout.setf(ios::fixed);
    		cout.setf(ios::showpoint);
    		cout.precision(2);
    		
    		cout<<"You withdrew $"<<withdraw<<endl;
    		cout<<"Your remaining balance is $"<<balance<<endl;
    	continue;
    	case 3:
    		cout<<"\n[[[DEPOSIT]]]\n";
    		cout<<"Enter amount: $";
    		cin>>deposit;
    		
    		balance = balance + deposit;
    		
    		cout.setf(ios::fixed);
    		cout.setf(ios::showpoint);
    		cout.precision(2);
    		
    		cout<<"You deposited $"<<deposit<<endl;
    		cout<<"Your new balance is $"<<balance<<endl;
    		continue;
    		case 4:
    		cout<<"\n***[[[EXIT MODE]]]***\n";
    		
    	break;
    
    
    	default:
    		cout<<"\n That is an invalid option \n";
    	}
    
    
    
    
    
    
    		break;
    	}
    	else
    
    	
    		cout<<"Pls try again!!!\n";}
    
    return 0;
    }//
    i'm almost done with my program except for this condition
    The program will only end when the user chooses to quit the program, otherwise the program should loop and prompt the users for actions.
    pls help me!!!=(

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,777
    You seriously need to get the hang of indentation.
    Your poor indentation makes the code very difficult to read.
    And your problem is not a difficult one. You need to think of proper logic. Use a loop that loops until the user enters quit. If the user enters incorrect password three times, you can break the loop using break.
    And as for 3 wrong password attempts... well, you can use a loop that asks the user for the password 3 times and sets a flag if the login is correct. If correct, you could simply break the loop.
    Outside, the program must detect if the login did not succeed and if so, then break the main loop and quit.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    First, I'd like to point out that you really need to work on your indentation. It makes it much easier to read and modify the code.

    And about your problem, you need a loop that will run at least the first time, then check if the user wants to quit at the end of it.

    Basically, I think a do... while(); loop would work best
    I might not be a pro, but I'm usually right

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21