Textual menus work by showing text items where each item is numbered. The menu would have items 1 to n.
The user makes a choice, then that causes a function to run, given the user made a valid choice. If the choice is invalid an error message is shown. Whatever choices was made, after the action of that choice happens, the menu repeats, unless the menu option is to quit. Such kind of menus are displayed from the code under main.
The menu items in this assignment are about simple sample of a bank account.
Here are the menu items:
1. Show Balance: the balance info would be stored in a variable declared in main
2. Make a Deposit: ask the user for the amount to deposit then call function Deposit to return the new balance. Deposit uses two parameters. The first represents the current balance and the second represents the amount to be deposited. The function rejects any deposit of 10,000.00 or more, or a deposit amount of 0 or less. Example of the code from main: current_balance = deposit(current_balance,amount)
3. Make a Withdrawal: ask the user for the amount to withdraw then call function Withdraw to return the new balance. Withdraw uses two parameters. The first represents the current balance and the second represents the amount to be withdrawn. The function rejects any withdrawals of amounts 0 or less, or amounts that cause the balance to be less than 10. Return the new balance.
4. Quit. In this case show a message: Press Enter to continue then end the application when the user presses the enter key.
Remember, if the choice made is not 1 to 4, show an error message asking the user to enter numbers 1 to 4, and to try again + Press Enter to continue then repeat the menu.
Do not use goto or break statements.
Menu items are typically processed using a switch statement. Using break inside a switch statement is always OK to ensure the other choices are not considered.
Make sure to add comments to clarify each of the functions you write, and add Top Level Comments. Do not comment every line of code.
Functions are supposed to be boxes with input/output – no interaction with the outside world. Check out A Function As A Box for more details.
Back to Module 7.
PreviousNext