GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 4.50 average.
  #1  
Old 06-Feb-2008, 03:04
cplus2x cplus2x is offline
New Member
 
Join Date: Feb 2008
Posts: 6
cplus2x has a little shameless behaviour in the past

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.

CPP / C++ / C 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.
Last edited by admin : 06-Feb-2008 at 17:39. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 06-Feb-2008, 03:31
jov0708 jov0708 is offline
New Member
 
Join Date: Feb 2008
Posts: 12
jov0708 is on a distinguished road

Re: c++ program for ATM machine


enclose the codes you want to execute in a loop with the while statement and break out of it when the user chose to quit.

CPP / C++ / C Code:
int option = 0;
while (option != 4) {
    cout << "Automated..."
    .
    .
    .
    cout << "Pls try again..."
}
  #3  
Old 06-Feb-2008, 03:37
cplus2x cplus2x is offline
New Member
 
Join Date: Feb 2008
Posts: 6
cplus2x has a little shameless behaviour in the past

Re: c++ program for ATM machine


I don't know exactly where to put that codes, can you please do it for me? Please...
  #4  
Old 06-Feb-2008, 06:17
davis
 
Posts: n/a

Re: c++ program for ATM machine


Begging is not a very impressive display of your coding skills...

http://www.math-cs.gordon.edu/courses/cs211/ATMExample/


:davis:
  #5  
Old 06-Feb-2008, 06:40
cplus2x cplus2x is offline
New Member
 
Join Date: Feb 2008
Posts: 6
cplus2x has a little shameless behaviour in the past

Re: c++ program for ATM machine


xory if it looks like i'm begging but i'm just asking how cuz im a newbie when it comes to c++, the link you gave me, i see that the codes are java if i'm ryt,, anyway we havent reach that topic yet, all i'm asking is for a simple ATm machine , actually im almost done but the problem is it end after i'm done with first options, example i was able to log in for the orret password, atm machine will give four options,
if i choose deposit,example i deposit 5000, it will prompt for what i deposit which is 5000 and at the same time, it will prompt 15000 as the total amount because i declared my initial balance as 10000
double balance = 10000;
now how about if i want to deposit again or withdraw, how to do it ? since my program ends after selecting one of the options,... what i want to happen here is that IT wiLL only terminate if me as the user will be the one to quit... pls help me.. this is now begging..hehehe!pls.. =p thanks in advance!!!!
  #6  
Old 06-Feb-2008, 07:43
nawoc nawoc is offline
New Member
 
Join Date: Feb 2008
Location: Stafford
Posts: 4
nawoc is on a distinguished road
Smile

Re: c++ program for ATM machine


I have updated your code to put the menu system in a loop until the user selects quit. I've commented where appropriate, I hope this helps

CPP / C++ / C Code:
int main()

{
	
	int password;

for (int i=0;i<3;i++)

{cout <<"enter password:\n";
	cin>>password;
	
	/* loop through 3 attempts at password */
	if (password==123456) {
		cout<<"korek!!!\n";
		break; }
	else
		cout<<"Please try again!\n";
	if (i == 2) return 0; // if failed 3 times, end program
	} /* end password loop */


	double balance = 10000;
	double withdraw, deposit;
	int option;
	bool finished = false; // if user selects option 4, 'quit', finished = true, otherwise finished = false
cout<<"\n";
cout<<"           ***MOGOL***\n";
	cout<<"*** Automated Teller Machine***"<<endl;
	while (!finished) { // repeat until user selects quit
	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:
			finished = true; // user has selected quit
		cout<<"\n***[[[EXIT MODE]]]***\n";
		
	break;


	default:
		cout<<"\n That is an invalid option \n";
	}


}
return 0;
}//
  #7  
Old 07-Feb-2008, 05:09
cplus2x cplus2x is offline
New Member
 
Join Date: Feb 2008
Posts: 6
cplus2x has a little shameless behaviour in the past

Re: C++ program for ATM machine


NAWOC, thanks a lot! I'll check that if that will works. Actually, I already got the code right, some friend of mine help me, it took us almost an hour. What he did is...

CPP / C++ / C Code:
/*
***Automated Teller Machine with authentication routine***
by MikhaeL Franko T. Mogol
*/
#include<iostream.h>


int main()

{
	double balance = 10000;
	double withdraw, deposit;
	int option;
	int password;

cout <<"enter password:\n";
	cin>>password;
if (password==123456)
for (int i=0;i<3;i++)

do{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";
	}while(//statement...blah blah, somewhere here,he put some condition, yah it definitely works!!!






		break;
	}
	else

	
		cout<<"Pls try again!!!\n";}

return 0;
}//

Anyway, nawoc.. thanks a lot, I'll study that code and see, check if that will works. Thanks!
Last edited by admin : 07-Feb-2008 at 23:54. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
Text-Based Roulette Game mfm1983 C++ Forum 5 29-Nov-2006 12:20
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 03:48
Pipeline freeze simulation darklightred C++ Forum 6 27-Jul-2006 19:37
How to read particular memory location ? realnapster C Programming Language 10 10-May-2006 09:11

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:22.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.