need help! math problem cant get values to sum

Hi, i know im not supposed to post HW questions but i am out of time and i cant figure my problem out.
My task was to create a ATM menu for deposits and to check my balance. the problem i am having is i can not make my deposits value sum with other vales from previous deposits. Also i do not know how to make the total transcend into another while loop to be displayed in check balance. the equation is from line 36-41 and needs to be displayed on lines 98-101. Please its due at 11 tonight and im just stuck have spent hours getting this far. please help this is my first C++ code.
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
#include <iostream>
using namespace std;
int main(int argc, char * const argv[])
{
	{int mainMenu;
		
		cout << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
		cout<<"welcome to My BAnk ATM"<<endl;
		cout<<"Your Friend in the Market"<<endl;
		cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
		cout<< "How can I Help you Today?"<<endl;
		cout<< "1)Deposit Money"<<endl;
		cout<< "2)Check Balance"<<endl;
		cout<< "3)Nothing, Exit"<<endl;
		cin>>mainMenu;

	while (mainMenu !=3)
		{
		
			if (mainMenu==1)
			{	 
			 cout<<"Thank you for Depositing Funds Today"<<endl;
			 cout<<"Please Make Your Selection"<<endl;
			 cout<<"	 1)Deposit into Checking"<<endl;
			 cout<<"	 2)Deposit into Savings"<<endl;
			 cout<<"	 3)Back to Main Menu"<<endl;
					int depositeMenu;
					cin>>depositeMenu;

				while(depositeMenu !=3) 
				
			{
			if(depositeMenu==1)
			{
			{
			 double checkingAcc;
			 double mydollar;
			 mydollar=0;
	cout<<"please enter dollar amount to be deposited into checking"<<endl;
	{ cin>> mydollar; cout<<"$";
							 checkingAcc=checkingAcc+mydollar;}// need to make checkingAcc give accurate results
							
								cout<<"============================================"<<endl;
		cout<<"Thank you for Depositing Funds Today"<<endl;
		cout<<"Please Make Your Selection"<<endl;
		cout<<"			1)Deposit into Checking"<<endl;
		cout<<"			2)Deposit into Savings"<<endl;
	        cout<<"			3)Back to Main Menu"<<endl;
	     cin>> depositeMenu;
	cout<<"--------------------------------------------"<<endl;
	}
	  else if (depositeMenu==2)
	{	
	  {
	double savingAcc=0;
	double mydollar;
	mydollar=0;
	cout<<"Please enter dollar amount to be deposited into savings"<<endl;
        {cin>>mydollar;
	savingAcc=savingAcc+mydollar;}
	cout<<savingAcc;
	}
	 // need to make savingAcc give accurate results
								cout<<"==========================================="<<endl;
								cout<<"Thank you for Depositing Funds Today"<<endl;
								cout<<"Please Make Your Selection"<<endl;
								cout<<"			1)Deposit into Checking"<<endl;
								cout<<"			2)Deposit into Savings"<<endl;
								cout<<"			3)Back to Main Menu"<<endl;
								cin>> depositeMenu;
								cout<<"--------------------------------------------"<<endl;
							 }
						 else
							{
							cout<<"============================================"<<endl;
							cout<<"Invalid Entry, Please Try Again"<<endl;
							cout<<"Please Make Your Selection"<<endl;
							cout<<"			1)Deposit into Checking"<<endl;
							cout<<"			2)Deposit into Savings"<<endl;
							cout<<"			3)Back to Main Menu"<<endl;
							cin>> depositeMenu;
							cout<<"--------------------------------------------"<<endl;
							}
						}
						{
						cout<< "How can I Help you Today?"<<endl;
						cout<< "1)Deposit Money"<<endl;
						cout<< "2)Check Balance"<<endl;
						cout<< "3)Nothing, Exit"<<endl;
						cin>>mainMenu;
						}
					}
				
			else if (mainMenu==2)
						{
						double savingAcc ;
						cout<< "Your Saving Balance =" <<cout<< savingAcc <<endl; 
						double checkingAcc;				
						cout<<"Your Checking Balance =" <<cout<< checkingAcc <<endl; 
						cout<<"============================================="<<endl;
						cout<<"Please Make A Choice"<<endl;
						cout<< "1)Deposit Money"<<endl;
						cout<< "2)Check Balance"<<endl;
						cout<< "3)Nothing, Exit"<<endl;
						cin>>mainMenu;
						cout<<"--------------------------------------------"<<endl;
						}
					
					
			else
			{
			cout<<"invalid Answer, Try Again"<<endl;
			cout<< "1)Deposit Money"<<endl;
			cout<< "2)Check Balance"<<endl;
			cout<< "3)Nothing, Exit"<<endl;
			cin>>mainMenu;
			}
	}}cout<<"===================================="<<endl;
	  cout<<"Thank you for your business Today"<<endl;
	  cout<<"Hope to see you sometime soon...Bye."<<endl;
	  cout<<"====================================" <<endl;
return 0;
}
Last edited on
Please, use "code" tags to make program readable.

Why 2 brackets?
1
2
3
int main(int argc, char * const argv[])
{
{int mainMenu;


as far as the extra bracket im not sure think i just got carried away. i feel i can get away with having to many versus not having enough.

also i added the code tags
Last edited on
Uh no you didnt
figured it out sorry 3hrs of sleep in the last 3 days so im pretty much useles
Last edited on
> ... the equation is from line 36-41 and needs to be displayed on lines 98-101.

Remove variables checkingAcc and savingAcc in local scopes of each menu option.

For example,
1
2
3
4
5
    else if (depositeMenu==2)
	{	
	  {
	     // double savingAcc=0; // *** remove this
             // .... 


And put these right on top, at the beginning of main().
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
    double checkingAcc = 0.0 ;
    double savingAcc = 0.0 ;
    
    // ...

	while (mainMenu !=3)
	{
            // ....
	    // all the nested while - if - while etc ... 
            // ....
	}
}
Last edited on
appreciate the help, makes sense to pull it out so they are included in everything. with the code as is i get this responce for my balance


Your Saving Balance =0xa091d50446
Your Checking Balance =0xa091d50446
=============================================
Please Make A Choice
1)Deposit Money
2)Check Balance
3)Nothing, Exit

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
#include <iostream>
using namespace std;
int main(int argc, char * const argv[])
{   
	{int mainMenu;
		double checkingAcc = 0.0 ;
		double savingAcc = 0.0 ;
		double mydollar=0.0;
			
		cout << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
		cout<<"welcome to My BAnk ATM"<<endl;
		cout<<"Your Friend in the Market"<<endl;
		cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
		cout<< "How can I Help you Today?"<<endl;
		cout<< "1)Deposit Money"<<endl;
		cout<< "2)Check Balance"<<endl;
		cout<< "3)Nothing, Exit"<<endl;
		cin>>mainMenu;

	while (mainMenu !=3)
		{
		
			if (mainMenu==1)
			{	 
			 cout<<"Thank you for Depositing Funds Today"<<endl;
			 cout<<"Please Make Your Selection"<<endl;
			 cout<<"	 1)Deposit into Checking"<<endl;
			 cout<<"	 2)Deposit into Savings"<<endl;
			 cout<<"	 3)Back to Main Menu"<<endl;
					
					int depositeMenu;
					cin>>depositeMenu;

				while(depositeMenu !=3) 
				
					{
					if(depositeMenu==1)
			
						{
						cout<<"please enter dollar amount to be deposited into checking"<<endl;
						cin>> mydollar; cout<<"$";
						checkingAcc=checkingAcc+mydollar;
						mydollar=0;							
					cout<<"============================================"<<endl;
					cout<<"Thank you for Depositing Funds Today"<<endl;
					cout<<"Please Make Your Selection"<<endl;
					cout<<"			1)Deposit into Checking"<<endl;
					cout<<"			2)Deposit into Savings"<<endl;
					cout<<"			3)Back to Main Menu"<<endl;
					cin>> depositeMenu;
					cout<<"--------------------------------------------"<<endl;
						}
					else if (depositeMenu==2)
						{
						cout<<"Please enter dollar amount to be deposited into savings"<<endl;
						cin>>mydollar;
						savingAcc=savingAcc+mydollar;
						mydollar=0;
						cout<<savingAcc;
	
								cout<<"==========================================="<<endl;
								cout<<"Thank you for Depositing Funds Today"<<endl;
								cout<<"Please Make Your Selection"<<endl;
								cout<<"			1)Deposit into Checking"<<endl;
								cout<<"			2)Deposit into Savings"<<endl;
								cout<<"			3)Back to Main Menu"<<endl;
								cin>> depositeMenu;
								cout<<"--------------------------------------------"<<endl;
						}
					else
							{
							cout<<"============================================"<<endl;
							cout<<"Invalid Entry, Please Try Again"<<endl;
							cout<<"Please Make Your Selection"<<endl;
							cout<<"			1)Deposit into Checking"<<endl;
							cout<<"			2)Deposit into Savings"<<endl;
							cout<<"			3)Back to Main Menu"<<endl;
							cin>> depositeMenu;
							cout<<"--------------------------------------------"<<endl;
							}
						}
						{
						cout<< "How can I Help you Today?"<<endl;
						cout<< "1)Deposit Money"<<endl;
						cout<< "2)Check Balance"<<endl;
						cout<< "3)Nothing, Exit"<<endl;
						cin>>mainMenu;
						}
					}
				
			else if (mainMenu==2)
						{
					
						cout<< "Your Saving Balance =" <<cout<< savingAcc <<endl; 
								
						cout<<"Your Checking Balance =" <<cout<<
						checkingAcc <<endl; 
						cout<<"============================================="<<endl;
						cout<<"Please Make A Choice"<<endl;
						cout<< "1)Deposit Money"<<endl;
						cout<< "2)Check Balance"<<endl;
						cout<< "3)Nothing, Exit"<<endl;
						cin>>mainMenu;
						cout<<"--------------------------------------------"<<endl;
						}
					
					
			else
			{
			cout<<"invalid Answer, Try Again"<<endl;
			cout<< "1)Deposit Money"<<endl;
			cout<< "2)Check Balance"<<endl;
			cout<< "3)Nothing, Exit"<<endl;
			cin>>mainMenu;
			}
	}}cout<<"===================================="<<endl;
	  cout<<"Thank you for your business Today"<<endl;
	  cout<<"Hope to see you sometime soon...Bye."<<endl;
	  cout<<"====================================" <<endl;
return 0;
}
Make this change
1
2
3
4
//cout<< "Your Saving Balance =" <<cout<< savingAcc <<endl;
//cout<<"Your Checking Balance =" <<cout<< checkingAcc <<endl; 
cout<< "Your Saving Balance =" << savingAcc <<endl;
cout<<"Your Checking Balance =" << checkingAcc <<endl;


And how many times have you repeated this?
1
2
3
4
cout<<"Please Make Your Selection"<<endl;
cout<<"			1)Deposit into Checking"<<endl;
cout<<"			2)Deposit into Savings"<<endl;
out<<"			3)Back to Main Menu"<<endl;


Can you do anything to avoid the repetition in code?
Last edited on
I would just like to say thanks JLBorges, My assignment is behaving properly now thanks to you.

but i feel if i used the term "for" i could somehow repeat or return to the main menu options. still just trying to understand what exactly "for" does.
You are going to drive your teacher nuts with your spacing/formatting. You don't need to keep indenting farther in if it's all part of the same while statement. Would you want to read that assignment? Go read some example programs off the net or from your book to see how formatting should look.

In case you don't know if you highlight a chunk of your code and press tab it indents to the right and shift + tab indents to the left.

"for" indicates a For loop. These are used when you want to repeat a loop and you know the specific number of times you want it to repeat. I'll let you google more information about how to make them.

So i have decided that the operation "do" should be the best. I have the program set up right i hope. but the code only cycles though the "while" once. i have tried while(statement && statement) to do multiple responses but i cant seem to get the depositMenu to go back to the do statement.

thanks for the question, it was a useful. ill be asking my teacher tomorrow lets hope he can figure it out.

do line 11,

1st while line 26,

2nd while line 39

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
#include <iostream>
using namespace std;
int main(int argc, char * const argv[])
{   
 {int mainMenu;
  int depositeMenu;
  double checkingAcc = 0.0 ;
  double savingAcc = 0.0 ;
  double mydollar=0.0;
			
	do
		{	 
		cout << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
		cout<<"welcome to My BAnk ATM"<<endl;
		cout<<"Your Friend in the Market"<<endl;
		cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
		cout<< "How can I Help you Today?"<<endl;
		cout<< "1)Deposit Money"<<endl;
		cout<< "2)Check Balance"<<endl;
		cout<< "3)Nothing, Exit"<<endl;
		cin>>mainMenu;				
		}
				
			

		while (mainMenu!=1 && mainMenu!=2);
		{		
		if (mainMenu==1)
			{
			cout<<"============================================"<<endl;
			cout<<"Thank you for Depositing Funds Today"<<endl;
			cout<<"Please Make Your Selection"<<endl;
			cout<<"			1)Deposit into Checking"<<endl;
			cout<<"			2)Deposit into Savings"<<endl;
			cout<<"			3)Back to Main Menu"<<endl;
			cin>> depositeMenu;
			cout<<"--------------------------------------------"<<endl;			
			
			while(depositeMenu!=3);
				{
					if(depositeMenu==1)
					{
					cout<<"please enter dollar amount to be deposited into checking"<<endl;
					cin>> mydollar; cout<<"$";
					checkingAcc=checkingAcc+mydollar;
					mydollar=0;	
					cout<<"============================================"<<endl;
					cout<<"Thank you for Depositing Funds Today"<<endl;
					cout<<"Please Make Your Selection"<<endl;
					cout<<"			1)Deposit into Checking"<<endl;
					cout<<"			2)Deposit into Savings"<<endl;
					cout<<"			3)Back to Main Menu"<<endl;
					cin>> depositeMenu;
					cout<<"--------------------------------------------"<<endl;						
					}
					else if (depositeMenu==2)
					{
					cout<<"Please enter dollar amount to be deposited into savings"<<endl;
					cin>>mydollar;
					savingAcc=savingAcc+mydollar;
					mydollar=0;
					cout<<savingAcc;
					cout<<"============================================"<<endl;
					cout<<"Thank you for Depositing Funds Today"<<endl;
					cout<<"Please Make Your Selection"<<endl;
					cout<<"			1)Deposit into Checking"<<endl;
					cout<<"			2)Deposit into Savings"<<endl;
					cout<<"			3)Back to Main Menu"<<endl;
					cin>> depositeMenu;
					cout<<"--------------------------------------------"<<endl;
					}
					else
					{
					cout<<"============================================"<<endl;
					cout<<"Invalid Entry, Please Try Again"<<endl;
					cout<<"Please Make Your Selection"<<endl;
					cout<<"			1)Deposit into Checking"<<endl;
					cout<<"			2)Deposit into Savings"<<endl;
					cout<<"			3)Back to Main Menu"<<endl;
					cin>> depositeMenu;
					cout<<"--------------------------------------------"<<endl;
					}
				}
						
					
			}
					
				
		else if (mainMenu==2)
		{
		cout<< "Your Saving Balance =" << savingAcc <<endl;
		cout<<"Your Checking Balance ="<< checkingAcc <<endl; 
		cout<<"============================================="<<endl;
		cout<<"Please Make A Choice"<<endl;
		cout<< "1)Deposit Money"<<endl;
		cout<< "2)Check Balance"<<endl;
		cout<< "3)Nothing, Exit"<<endl;
		cin>>mainMenu;
		cout<<"--------------------------------------------"<<endl;
		}
					
					
		else
		{
		cout<<"invalid Answer, Try Again"<<endl;
		cout<< "1)Deposit Money"<<endl;
		cout<< "2)Check Balance"<<endl;
		cout<< "3)Nothing, Exit"<<endl;
		cin>>mainMenu;
		}
	}
	}
	cout<<"===================================="<<endl;
	cout<<"Thank you for your business Today"<<endl;
	cout<<"Hope to see you sometime soon...Bye."<<endl;
	cout<<"====================================" <<endl;
return 0;
}
Last edited on
Topic archived. No new replies allowed.