Calling functions and looping menu

Hey, everyone. Working on a pretty basic banking program for class. It's in the skeleton stage right now. But I'm having issues. I'm trying to call the, mostly empty functions into the case so that when the user inputs their menu selection it will call the function and output whatever they are looking for. Then I need the menu to loop back after they've made their selection until they choose to exit, but I'm not sure how to do it. My knowledge base is limited to I'm having a hard to finding solutions for my current level. Any suggestions on the best way to call the function and make the menu loop? Thanks.


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
 class account
{
	double balance;

	void addAcct();
	void deposit(double);
	void withdrawal(double);
	void funds_transfer();
	void acct_info();
	void transction_his();
};

void account::addAcct()
	{
	printf("\nAdding accounts is not possible at this time");
	}

void account::deposit(double x)
{
	balance += x;

}

void account::withdrawal(double x)
{


}

void account::funds_transfer()
{

}

void account::acct_info()
{
	printf("\nCustomer account holder information is unavailable at this time");
}

void account::transction_his()
{
	printf("There is no transaction history available at this time");
}

int main()
{ 
	int choice;
	bool menu = true;
	
	do
	{
		printf("1. Create New Account\n");
		printf("2. Cash Deposit\n");
		printf("3. Cash Withdrawl\n");
		printf("4. Fund Transfer\n");
		printf("5. Account information\n");
		printf("6. Transaction information\n");
		printf("7. Exit\n\n");
		printf("Press a choice between the range [1-7]\n\n");
		scanf_s("%d", &choice);
			
		
		switch (choice)
		{
		case 1:
			void addacct();
			break;

		case 2:
			printf("This is where you would deposit money\n");
			printf("Press any key to continue");
			scanf_s("%d", &choice);
			break;

		case 3: 
			printf("This is where you would withdraw cash\n");
			printf("Press any key to continue");
			scanf_s("%d", &choice);
			break;

		case 4: 
			printf("This is where you would withdraw cash\n");
			printf("Press any key to continue");
			scanf_s("%d", &choice);
			break;

		case 5:
			printf("This is where you would see your account information\n");
			printf("Press any key to continue");
			scanf_s("%d", &choice);
			break;

		case 6: 
			printf("This is where you would see your transaction information\n");
			printf("Press any key to continue");
			scanf_s("%d", &choice);
			break;

		case 7:
			printf("Are you sure you want to exit? <Y/N>\n");
			break;
		
		default:
			printf("Your input is out of range! Enter a choice between 1 to 7!");
			break;
		}

	} while (choice != 7);

    return 0;
}
Last edited on
Lines 5-10: All your functions are private. You need to make then public if you expect to call them from your menu.

Line 4: You need a constructor for account to initialize balance to zero.

Line 15: Why are you using printf in a C++ program? Have you learned cout yet?

Line 60: Why are you using scanf in a C++ program? Have you learned cin yet?

Line 66: This is a function declaration, not a function call. Remove the void.

Line 71-72: These are common to all cases, you want to put then at the bottom of your loop.

Line 49: You need an instance of account if you expect to call its functions. i.e.
1
2
 
  account acct;


Line 66: You can only call addacct relative to an instance of an account object.
 
  acct.addacct ();


PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.



Last edited on
Thanks for looking at my code. I used the good tags changed my functions to public and questions if you don't mind. When I've move lines 71-72 and all the other printf and scanfs at the bottom of my loop, it should still be inside the loop correct? Also I removed the void now my funtion is undeclared. Do I need to go in and declare it in main? I'm guessing after default maybe? Sadly I have not learned cout and cin yet, my teacher doesn't want us using them yet.
Thanks for adding code tags.

When I've move lines 71-72 and all the other printf and scanfs at the bottom of my loop, it should still be inside the loop correct?

Assuming you mean after line 106, then yes.

Also I removed the void now my funtion is undeclared. Do I need to go in and declare it in main?

No. Read what I posted before about declaring an instance of account.


Line 49: You need an instance of account if you expect to call its functions. i.e.
1
2
 
    account acct;


Line 66: You can only call addacct relative to an instance of an account object.
1
2
 
  acct.addacct ();




Topic archived. No new replies allowed.