ATM machine not exiting due thursday

So my project is to include 2 accounts checking and savings that both start at 1000 and can have funds transfer between accounts, funds be withdrawn, and deposited. I'm stuck... the program wont break when trying to return to menu and just selects option 1. let me know if you can help please this project is due thursday!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

#include <iostream>
#include <iomanip>
using namespace std;
//Function prototypes

void showMenu();
int mainMenuSelection(int);

double enterAmountScreen(double);
int main()
{
	//variables
	int choice;

	//Set the numeric output formatting
	cout << fixed << showpoint << setprecision(2);
	//Function for welcome screen


	//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 = 1000.00;
	//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 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)
		{
			break;
		}
		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

//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;
}
I think that you are not calling your enterAmountScreen() function properly.
It is not a void function that you can directly call. It return a double.
So you have to declare a variable of type double and set it equal to the function to call it.
For ex:
1
2
double myMoney;
myMoney = enterAmountScreen(money);

This is how you usually call a non-void function.

And you don't need this statment in every case.
1
2
3
4
if (choice == 3)
		{
			showMenu();
		}

You can just put this outside your switch statement. The less lines of code you have, the better it is.
Last edited on
closed account (2LzbRXSz)
I tried everything - through cin.ignore() after all your cin statements, everything...

Then... I found the culprit... Or so I thought.

enterAmountScreen(money); is just kind of hanging around.

The real culprit is inside your do-while statements - you need to check if withdrawChoice == 4;
Inside the if statements, put showMenu();

But showMenu(); only displays the menu. It doesn't get the user's input after the display.

So move
1
2
3
4
5
6
7
8
9
10
11
12
13
   int decision;
   cin >> choice;
        cin.ignore();
        //Validate the menu selection.
        while (choice < 1 || choice > 5)
        {
            cout << "Please enter 1, 2, 3, 4, or 5: ";
            cin >> choice;
            cin.ignore();
        }
        
        //Function to choose in the main menu selection
        mainMenuSelection(choice);
to inside your showMenu(); function.

Edit:
1
2
3
case 5:
            cout << "Program ending." << endl << endl;
            break;


Rather than having it break, you can just call exit(0); and it'll end the program.
Last edited on
okay so I am redoing this project as I need to use a header file with a main and source cpp.

I have not much so far and am a horrible coder. I would like step by step help if anyone is willing to skype or even help through here.

so far I have

header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

class bankAtm
{
public:
	void checkAccount();
	void savAccount();
	void bankTrans();
	void bankWithdrawal();
	void balAccount();
	void getBal();
	void setBal();

private:
	double bankBal;

};

void showBankMenu(bankAtm &);
void manageAtm(bankAtm &, bankAtm &);

source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "ATM.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	bankAtm checkAccount();
	bankAtm savAccount();

	do
	{
		system("CLS");
		cin.clear();
	}
	while ()
	{

	}
}

main
1
2
3
4
5
6
7
#include <iostream>
#include <iomanip>
using namespace std;
#include "ATM.h"




project question:
handle at least 2 accounts
transfer funds between them
withdraw from either account
balance inquire on either account
deposit to either account
must be menu driven
each account must start with $1000

The teacher will check the program for errors like using a letter and breaking the code and what not. Please help me in anyway possible I am not interested in learning code in c++ or should not need it for my cyber security degree as I am focusing on pen testing!
Topic archived. No new replies allowed.