I am writing an atm program for a class and will enclose the instructions. I really want to just write a section of code and make sure I am doing it right before I move on. I am starting with the main menu and was wanting to know if someone could look at the instructions and make sure I did this correctly...

assumptions
1 - only direct account transactions will be done on this ATM
2 - assume this ATM is a bank ATM, no transaction fees
3 - this application will be a 'dos' application
4 - app should be able to cancel at any point via back (goes to main menu, screen 4 and beyond) or exit atm (screens 2 & 3)
5 - max 3 times to log in, after 3 times = show message "your account has been locked."
6 - this is a swipe machine
7 - every screen will have a feedback line on line 1
8 - Can only hold 10,000 dollars before ATM out of order (effects withdrawls, deposits and maintenance screen)
9 - Any withdrawl has to be in $20 amounts, transfers don't have this limitation
10 - Account files will be prepopulated
11 - User can only withdrawl $300 amount per day
12 - Every transaction has a date/time stamp, account #
/* 13 - Information only on screen, or printed/receipts */


Welcome Screen (screen 1)
"hit enter to simulate inserting card"

Data Entry Screen (screen 2)
1) account pin: (resides in a file)
2) exit ATM
-if valid got to main menu
-else, display "invalid account # and/or pin#"

Main Menu Screen (screen 3)
1) withdrawl
2) deposit
3) check balance
4) funds transfer
5) exit ATM

Withdrawl Screen (screen 4.a)
1) from checking
2) from savings
3) quick cash /* optional */
4) back to main menu

Deposit Screen (screen 4.b)
1) to checking
2) to savings
3) back to main menu

Check Balance Screen (screen 4.c)
1) from checking
2) from savings
3) back to main menu

Funds Transfer Screen (screen 4.d)
1) from savings to checking
2) from checking to savings
3) back to main menu

Enter Amount Screen (screen 5.a)
1) Enter Amount
2) back to main menu

/* Quick Cash Amount Screen (screen 5.b)
1) $20.00
2) $40.00
3) $60.00
4) $80.00
5) $100.00
6) back to main menu */

Would you like to perform another transaction (screen 6)
-if yes, go back to screen 2
-else, go to screen 7

Goodbye Screen (screen 7)
display goodbye message, wait 10 seconds, cycle back to welcome screen

/* optional
Maintenance Screen (screen 8)
requires a special pin
1) update money supply
2) exit ATM */

here is my code...

//Class: C++ 230
//Date: 2/16/10
#include <iostream>
using namespace std;

//Function prototypes
void showMenu();

int main ()
{
	//Declare variables
	int choice;

	//Set the numeric output formatting
	//cout << fixed << showpoint << setprecision(2);

	do
	{
		//Display the menu and get the user's choice.
		showMenu();
		cin >> choice;

		//Validate the menu selection.
		while (choice < 1 || choice > 5)
		{
			cout << "Please enter 1, 2, 3, 4, or 5: ";
			cin >> choice;
		}
	}
	return 0;
}
	

	void showMenu()
	{
		//Display the main menu screen
		cout << endl << "\t\tMain Menu Screen" << endl << endl;
		cout << "1) Withdrawal" << endl;
		cout << "2) Deposit" << endl;
		cout << "3) Check Balance" << endl;
		cout << "4) Funds Transfer" << endl;
		cout << "5) Exit ATM" << endl << endl;
		cout << "Enter your choice: ";
	}
michealadejimi commented: PROJECT: Create an ATM class that should be bought by 5 different banks as subclasses. The ATM class should run a recursive function in its operations +0

Recommended Answers

All 15 Replies

Your do/while syntax is incorrect. It should be:

do{


}while(condition);

You're going to have to nest some of these menus so do a brief sketch on a piece of paper as to how they should be laid out.

Can someone give m any advice on why my code exits if i hit 5 but goes back to the main menu if i hit 1,2,3, or 4

//Class: C++ 230
//Date: 2/16/10
#include <iostream>
using namespace std;

//Function prototypes
void showMenu();
int mainMenuSelection(int);

int main ()
{
	//Declare variables
	int choice;

	//Set the numeric output formatting
	//cout << fixed << showpoint << setprecision(2);

	do
	{
		//Display the menu and get the user's choice.
		showMenu();
		cin >> choice;

		//Validate the menu selection.
		while (choice < 1 || choice > 5)
		{
			cout << "Please enter 1, 2, 3, 4, or 5: ";
			cin >> choice;
		}

		int mainMenuSelection(int);
		
	} while (choice != 5);
	return 0;
}
	
	void showMenu()
	{
		//Display the main menu screen
		cout << endl << "\t\tMain Menu Screen" << endl << endl;
		cout << "1) Withdrawal" << endl;
		cout << "2) Deposit" << endl;
		cout << "3) Check Balance" << endl;
		cout << "4) Funds Transfer" << endl;
		cout << "5) Exit ATM" << endl << endl;
		cout << "Enter your choice: ";
	}

	int mainMenuSelection(int choice)
	{
		int withdrawChoice,
		    depositChoice,
		    checkBalanceChoice,
		    fundsTransferChoice;

		//Respond to user's menu selection
		switch (choice)
		{
		case 1:
			cout <<"\t\tWithdrawal Screen" << endl << endl;
			cout << "1) From Checking" << endl;
			cout << "2) From Savings" << endl;
			cout << "3) Quick Cash" << endl;
			cout << "4) Back to Main Menu" << endl;
			cout << "Enter your withdraw choice: ";
			cin >> withdrawChoice;
			break;

		case 2:
			cout <<"\t\tDeposit Screen" << endl << endl;
			cout << "1) To Checking" << endl;
			cout << "2) To Savings" << endl;
			cout << "3) Back to Main Menu" << endl;
			cout << "Enter your deposit choice: ";
			cin >> depositChoice;
			break;

		case 3:
			cout << "\t\tCheck Balance Screen" << endl << endl;
			cout << "1) From Checking" << endl;
			cout << "2) From Savings" << endl;
			cout << "3) Back to Main Menu" << endl;
			cout << "Enter Your Check Balance Choice: ";
			cin >> checkBalanceChoice;
			break;

		case 4:
			cout << "\t\tFunds Transfer Screen" << endl << endl;
			cout << "1) From Savings to Checking" << endl;
			cout << "2) From Checking to Savings" << endl;
			cout << "3) Back to Main Menu" << endl;
			cout << "Enter Your Funds Transfer Choice: ";
			cin >> fundsTransferChoice;
			break;

		case 5:
			cout << "Program ending." << endl << endl;
			break;
		}
		return choice;
	}
int main ()
{
	//Declare variables
	int choice;
 
	//Set the numeric output formatting
	//cout << fixed << showpoint << setprecision(2);
 
	do
	{
		//Display the menu and get the user's choice.
		showMenu();
		cin >> choice;
 
		//Validate the menu selection.
		while (choice < 1 || choice > 5)
		{
			cout << "Please enter 1, 2, 3, 4, or 5: ";
			cin >> choice;
		}
 
		int mainMenuSelection(int);
 
[B]	} while (choice != 5);[/B]
	return 0;
}

That would be why. :)

Where on earth did int mainMenuSelection(int); come from? Looks like a function prototype to me.

I had it working before I added the switch into a function but after doing so it keeps repeating and I know it has to do with the while statement but just not able to figure it out.

this works when I do not use the switch statement in a function. I would like to use it in a function to keep main with as little data as possible but if I am not able to use it in a function or have any tips please let me know as I am stuck until I get this part figured out

Your do/while repeats until you hit a 5 to exit like restrictment said. Isn't that what you want? If not what behavior do you want?
Your inner while OTOH repeats the prompting when your input is outside of your range.

I apologize for not being clear. When I do not hit 1, 2, 3, 4, 5 it does exactly what it is supposed to by asking to enter 1,2,3,4,5. When I hit 5 it also does exactly what it is supposed to do and exits the program. My issue is when I hit 1,2,3, or 4. When I do this it just loops in my main menu screen. what I want it to is if I hit 1 go to the withdraw screen, hit 2 go to the deposit screen i have coded, etc, etc. Like I said when I dont use it in a function it works fine but have never used a switch in a function.

Line 32 is a function prototype, not a function call. You will have to address that issue for the function to work correctly. You will need to create a copy of that line somewhere above the beginning of your main(), then re-format that line into a proper function call.

Have a look at this for more info.

I have most of my errors fixed up but just have a couple additional problems. Whenever I hit the choice to go back to main menu it goes to the withdraw menu. I apologize as this may sound confusing but if you could just run my code you will see what I mean. The same is true from the last function of my code...

//Class: C++ 230
//Date: 2/16/10
//Assignment: final
#include <iostream>
#include <iomanip>
using namespace std;

//Function prototypes
void showMenu();
int mainMenuSelection(int);
void welcomeScreen();
double enterAmountScreen(double);

int main ()
{
	//Declare variables
	int choice;
	

	//Set the numeric output formatting
	cout << fixed << showpoint << setprecision(2);

	//Function for welcome screen
	welcomeScreen();
	
	//Create a do\while loop
	do
	{
		//Display the menu and get the user's choice.
		showMenu();
		cin >> choice;

		//Validate the menu selection.
		while (choice < 1 || choice > 5)
		{
			cout << "Please enter 1, 2, 3, 4, or 5: ";
			cin >> choice;
		}
		
		//Function to choose in the main menu selection
		mainMenuSelection(choice);

		
		
	} while (choice != 5);
	
	return 0;
}
	
//Function to show the main menu
void showMenu()
	{
		//Display the main menu screen
		cout << endl << "\t\tMain Menu Screen" << endl << endl;
		cout << "1) Withdrawal" << endl;
		cout << "2) Deposit" << endl;
		cout << "3) Check Balance" << endl;
		cout << "4) Funds Transfer" << endl;
		cout << "5) Exit ATM" << endl << endl;
		cout << "Enter your choice: ";
	}
	
//Function to choose in the main menu screen
int mainMenuSelection(int choice)
	{
		//Declare variables in mainMenuSelection
		int withdrawChoice,
		    depositChoice,
		    checkBalanceChoice,
		    fundsTransferChoice;
		double money = 0.0;

		//Respond to user's menu selection
		switch (choice)
		{
		case 1:
			do
			{
				cout <<"\t\tWithdrawal Screen" << endl << endl;
				cout << "1) From Checking" << endl;
				cout << "2) From Savings" << endl;
				cout << "3) Quick Cash" << endl;
				cout << "4) Back to Main Menu" << endl;
				cout << "Enter your withdraw choice: ";
				cin >> withdrawChoice;

				while (withdrawChoice < 1 || withdrawChoice > 4)
				{
					cout << "Please reenter 1, 2, 3, 4: ";
					cin >> withdrawChoice;
				}

				enterAmountScreen(money);

			} while (choice != 4);
			

			//Back to main menu option
			if (choice == 4)
			{
				showMenu();
			}
			break;

		case 2:
			do
			{
				cout <<"\t\tDeposit Screen" << endl << endl;
				cout << "1) To Checking" << endl;
				cout << "2) To Savings" << endl;
				cout << "3) Back to Main Menu" << endl;
				cout << "Enter your deposit choice: ";
				cin >> depositChoice;

				while (depositChoice < 1 || depositChoice > 3)
				{
					cout << "Please reenter 1, 2, or 3: ";
					cin >> depositChoice;
				}

				enterAmountScreen(money);

			} while (choice != 3);

			//Back to main menu option
			if (choice == 3)
			{
				showMenu();
			}
			break;

		case 3:
			do
			{
				cout << "\t\tCheck Balance Screen" << endl << endl;
				cout << "1) From Checking" << endl;
				cout << "2) From Savings" << endl;
				cout << "3) Back to Main Menu" << endl;
				cout << "Enter Your Check Balance Choice: ";
				cin >> checkBalanceChoice;

				while (checkBalanceChoice < 1 || checkBalanceChoice > 3)
				{
					cout << "Please reenter 1, 2, or 3: ";
					cin >> checkBalanceChoice;
				}

			} while (choice != 3);

			//Back to main menu option
			if (choice ==3)
			{
				showMenu();
			}
			break;

		case 4:
			do
			{
				cout << "\t\tFunds Transfer Screen" << endl << endl;
				cout << "1) From Savings to Checking" << endl;
				cout << "2) From Checking to Savings" << endl;
				cout << "3) Back to Main Menu" << endl;
				cout << "Enter Your Funds Transfer Choice: ";
				cin >> fundsTransferChoice;

				while (fundsTransferChoice < 1 || fundsTransferChoice > 3)
				{
					cout << "Please reenter 1, 2, or 3: ";
					cin >> fundsTransferChoice;
				}

				enterAmountScreen(money);

			} while (choice != 3);

			//Back to main menu option
			if (choice == 3)
			{
				showMenu();
			}
			break;

		case 5:
			cout << "Program ending." << endl << endl;
			break;
		}
		return choice;
	}
		
//Function to display the welcome screen
void welcomeScreen()
		{
			cout << "Hit enter to simulate inserting card";
			//Hit enter to go to the next screen
			cin.get();
		}

//Function to enter amount screen
double enterAmountScreen(double money)
		{
			int decision;
			
			cout << endl << "\t\tEnter Amount Screen" << endl;
			cout << "1) Enter Amount:";
			cout << endl << "2) Back to Main Menu:";
			cout << endl << "Enter your decision for the amount screen: ";
			cin >> decision;

			if (decision == 2)
			{
				showMenu();
			}
			else
			{
				cout << "Please enter the amount: ";
				cin >> money;
			}
			return money;
		}

Lines 84-94, have another look at how you are doing that. You need a way to bypass the call to the sub-menu. You have the same issue in all your case sections. The structure of enterAmountScreen() seems to be correct.

If possible, can you send me the entire completed bank ATM program? I shall be thankful, if you do so. My email id is <<snip>>

commented: Do your own work +0

can teach me how to make a c++ program to change pin in atm machine

Write an algorithm for an ATM program, where user will be required to key in password
before they proceed to the next process. The user not allowed to enter until give the
correct password. User will be given a choice like cash withdrawal, cash deposition,
balance checking and etc. Used your own creativity as what to put in your ATM
application. Consider that password and balance information already exist
The implementation of the algorithm must apply control & repetition method and
function (sub-routine). The use of pointers and array in the implementation, will be
result in higher marks.

PROJECT: Create an ATM class that should be bought by 5 different banks as subclasses. The ATM class should run a recursive function in its operations that should be executed using different functions. Them create 5 different bank branches for each of the 5 banks that bought the machines from the same manufacturers. To be submitted between now and exam. Date to be announced soon.

commented: grade: FAIL because you're too lazy to do your own homework -4
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.