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.
A Function As A Box
I have added an extra document to this unit regarding functions. I have copies its content below for your convenience:
A function should be treated like a closed box with an input cable and an output cable. All data the box processes should be passed through the cable, and all output is passed through the cable. The box cannot interact with the outside world other than through its input cable and output cable. Hence do not use any scanf or printf statements from within the box.
In an ideal world, if the function encounters an error and can not process the data as expected it is to return a value that we can agree on to imply an error. For example, in the deposit function, if the deposit amount is illegal, the function return -1. The calling code (from main) would then test the return value: if it is -1 then the calling code shows an error and balance is not changed, otherwise the balance is updated with the new value. If there are cases when -1 is a valid return value not indicating an error, then error or exception handling can be used to throw a runtime error but this is a non- preferred solution.
Submitting Assignments
For all your assignments, you must submit your work by uploading a file. Copy and Paste is not accepted as a way to submit your work. It will earn you 0 credit.
You will be required to zip all the files of your visual studio project into one compressed file rather than upload several files.
Use a compression utility such as PKZip to compress your files.
Use of rar to compress files is not accepted, and files compressed with rar will not earn credit.