Need assistance with a Banking code

I need help with some homework I have for a programming class.

I am supposed to make a bank account program that's able to have the default value of money set to 1000 and you should be able to deposit and withdraw money from it and check your current amount of money and it shouldn't be possible to withdraw more money than what exists on your bank account. I am supposed to do it with the help of Switch-case sets but I will come to that later

I have started building my program but I ran into a problem really, really early :<
Here's my program;
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
#include <iostream>
using namespace std;

int main()
{
	// menu
	char menu;
	int value;
	int money = 1000;
	 
	cout << "MENU" << endl << "1. Deposit" << endl << "2. Withdraw" << endl << "3. Show proceeds" << endl;
	cin >> menu;
	// Deposit
	if (menu = '1') {
		cout << "Chose amount of money you want to deposit :";
		cin >> value;
		money = money+value;
		cout << "You now have " << money << "$ in your bank account";
	}
	// Withdraw 
	
	else if (menu = '2') {
		cout << "Chose amount of money you want to withdraw :";
		cin >> value; 
		money = money - value; 
		cout << "You withdrew " << value << "$. You now have " << money << "$ on your bank account";
	}
	
	// Show proceeds
	else if (menu = '3') {

	}


return 0;
}


The problem is that the deposit menu works well but at the withdraw menu you are supposed to select the amount of money you want to withdraw from your account. Though my program is depositing the amount of money you choose instead of withdrawing it.

Can anyone help me?
if (menu = '1') {

Assign uses '='
Comparing uses '=='

Make sure you don't mix them up :)

You also don't need to put 1 in ' 's. It can be used on its own as an integer, i.e.
if (menu == 1) is valid.
My try I used switch statement

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
#include <iostream>
using namespace std;

int main()
{
	// menu
	char menu;
	int value;
	int money = 1000;
	
	 
	cout << "MENU" << endl << "1. Deposit" << endl << "2. Withdraw" << endl << "3. Show proceeds" << endl;
	cin >> menu;
	// Deposit
	switch(menu)
	{
    case '1': 
    {
		cout << "Chose amount of money you want to deposit :";
		cin >> value;
		money = money+value;
		cout << "You now have " << money << "$ in your bank account";
		getchar();
		break;
		
	}
	case '2':
	// Withdraw 
	
	{
		cout << "Chose amount of money you want to withdraw :";
		cin >> value; 
		money = money - value; 
		cout << "You withdrew " << value << "$. You now have " << money << "$ on your bank account";
		getchar();
        break;
	}
	
	// Show proceeds
	case '3':
	{

	}
}

getchar();
return 0;
}
Last edited on
Topic archived. No new replies allowed.