Question

Textual menus work by showing text items where each item is numbered. The menu would have...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int deposit(int current_balance, int amount)
{
if (amount >= 10000 || amount <= 0)
{
printf("Invalid amount cannot be deposited.\n\n");
}
else
{
current_balance = current_balance + amount;
}
return current_balance;
}

int withdraw(int current_balance, int amount)
{
if (amount <= 0 || current_balance - amount < 10)
{
printf("Invalid amount cannot be withdrawed.\n\n");
}
else
{
current_balance = current_balance - amount;
}
return current_balance;
}

int main()
{
int amount, choice;
int current_balance = 0;
do
{
printf("1. Show Balance\n2. Make a Deposit\n3. Make a withdrawal\n4. Quit\n\n");
scanf("%d", &choice);\
switch(choice)
{
case 1:
printf("The current balance is %d\n\n", current_balance );
break;
case 2:
printf("Enter the amount to deposit: ");
scanf ("%d", &amount);
current_balance = deposit(current_balance, amount);
break;
case 3:
printf("Enter the amount to withdraw:");
scanf ("%d", &amount);
current_balance = withdraw(current_balance, amount);
break;
case 4:
printf("QUIT\n");
return 0;
default:
printf("Invalid choice\n");
}
} while (choice != 4);
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Textual menus work by showing text items where each item is numbered. The menu would have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is for java programming Please use comments Use the Account class created in homework 8_2...

    this is for java programming Please use comments Use the Account class created in homework 8_2 to simulate an ATM machine. Create ten checking accounts in an array with id 0, 1, …, 9, initial balance of $100, and annualInterestRate of 0. The system prompts the user to enter an id between 0 and 9, or 999 to exit the program. If the id is invalid (not an integer between 0 and 9), ask the user to enter a valid...

  • Sample Execution – Level 3 Welcome to your Menu Creation system. How many items would you...

    Sample Execution – Level 3 Welcome to your Menu Creation system. How many items would you like to have on your menu? 2 Create your menu! Enter item #1: Coffee Enter the number of toppings: 2 Enter topping #1: Whipped Cream Enter topping #2: Cinnamon Enter item #2: Tea Enter the number of toppings: 2 Enter topping #1: Milk Enter topping #2: Sugar May I take your order? This is the menu: Coffee Tea Pop How many items would you...

  • C++ Check Book Program I need to have a checkbook program that uses the following items....

    C++ Check Book Program I need to have a checkbook program that uses the following items. My code that I have appears below. 1) Math operations using built-in math functions 2) Class type in a separate .h file with member functions (accessor functions, get, set, show, display find, etc). There needs to be an overloaded function base/derived classes or a template. 3) Binary File #include <iostream> using namespace std; int main() {     double checking,savings;     cout<<"Enter the initial checking...

  • 1- TigerOne Bank is a local bank that intends to install a new automated teller machine...

    1- TigerOne Bank is a local bank that intends to install a new automated teller machine (ATM) to allow its customers to perform basic financial transactions. Using the ATM machine users should be able to view their account balance, withdraw cash and deposit funds. The bank wants you to develop the software application that will be installed on the new ATM machines. The following are the requirements for the application:  Users are uniquely identified by an account number and...

  • Please help me with the code. Thank you! Description James Vond has delivered us some intel...

    Please help me with the code. Thank you! Description James Vond has delivered us some intel that the enemy perpetrators have been tricked into going to a bank that we've wired and booby-trapped. However, we have not gotten a bank system in place and you are the only person who is capable of handling such a task. We need this plan to go off without a hitch because the money we'll be receiving will give us insight on the hideout's...

  • GPA calculator: Assume the user has a bunch of courses they took, and need to calculate...

    GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work. We will create a textual menu that shows 3 choices. 1. Enter course grade and units. 2. Show GPA. 3....

  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • Your assignment is to create a restaurant ordering system where the cashier can create the menu...

    Your assignment is to create a restaurant ordering system where the cashier can create the menu and then take in the order and display the order back to the customer Sample Execution – Level 1 Welcome to your Menu Creation system. How many items would you like to have on your menu? 2 Create your menu! Enter item #1: Coffee Enter item #2: Tea This is the menu: Coffee Tea What would you like to order? Cake That isn’t on...

  • CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c...

    CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c that implements the following features. Implement this program in stages using stepwise refinement to ensure that it will compile and run as you go. This makes it much easier to debug and understand. This program presents the user a menu of operations that it can perform. The choices are listed and a prompt waits for the user to select a choice by entering a...

  • Python GPA calculator: Assume the user has a bunch of courses they took, and need to...

    Python GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work. We will create a textual menu that shows 3 choices. 1. Input class grade and number of units. 2....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT