is there a way to define a global variable?

You can pass total to a function with & in front of it. It is known as reference in C++ and you can modify given object inside a function, not only it’s copy. Examples. And in your code:

int deposit(int &total) { ...your code... }

Overall I don’t think calling menu inside every function is a good idea. With each function call you push it to a stack, which takes extra memory. Changing deposit and withdraw to void and using while(1) loop inside of main() to call menu() would be much better.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top