Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C LANGUAGE Lab 4 More Selection Structures In this lab, you will gain more practice with selection structures, specifically the if/else if or switch statements.

C LANGUAGE

Lab 4 More Selection Structures

In this lab, you will gain more practice with selection structures, specifically the if/else if or switch statements. In addition, you will experiment with new techniques for input and output, including the use of getchar() for character input and formatting sub-specifiers.

EXAMPLE PROGRAM

The sample program from Lab 3 continues to be a useful reference for this weeks lab.

YOUR PROGRAM

For your lab, you will write a small utility that will allow a user to check an account balance, deposit funds to an account, or withdraw funds from an account. To simulate an existing account, declare an variable to store the account balance, and initialize it to 1000.00.

To begin, display a menu to the user, similar to the one seen below. The menu options should use letter designations, not integers. After displaying the menu, allow the user to make their choice, and store the result in a variable using the getchar() method.

|~~ Account Management Menu ~~|

| |

| A) Check Account Balance |

| B) Deposit Funds |

| C) Withdraw Funds |

|~~~~~~~~~~~~~~~~~~~~~~~~~~|

Next, you will need to use a selection structure (or structures) to determine what option the user chose, and to execute the appropriate behavior in response. You can use either a series of if/else if statements, or a switch to accomplish this task. Your program should be case-insensitive to the users input, so you will need to ensure that it works with both capital and lowercase letters for input. The strategy to do this will depend largely on your choice of structures.

If the user chose Option A, you should display the users current account balance.

If the user chose Option B, you should prompt the user to enter the value of the deposit, display messaging indicating that you are depositing the entered value to the account, and then update the account balance variable by adding the newly deposited amount to it. Afterwards, display the newly updated account balance.

If the user chose Option C, you should again prompt the user to enter the value of the withdrawal. Before processing the withdrawal, however, you should use a nested if/else statement to confirm that the current account balance is sufficient to process the withdrawal. The account balance should not be allowed to reach negative values. If the account does contain enough money, then display messaging indicating that the withdrawal is being processed, update the account balance by subtracting the amount of the withdrawal, and then display the newly updated account balance. If the account contains insufficient funds to process the withdrawal, you should instead display messaging to this effect.

If the user chose an option other than A, B, or C, you should display a messaging indicating that they have made an invalid selection.

For now, our program will end after any of the three options are processed. Later, we will learn to return the user to the menu to allow them to make another selection. Examples of the type of messaging you should include can be found in the attached screenshots.

When you are done, name the .c file according to the following convention: [First Initial][Last Name]_Lab4.c. Submit the completed .c file through the Blackboard assignment submission tool (if you have any difficulties submitting, please contact the instructor).

Challenge (25 points extra credit):

After completing the lab using either if/else if statements or with a switch statement, complete it again using the other method for some quick extra credit. You can do this in the same source file by commenting out one of the methods, or in two separate files (in which case you would upload both of them).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analytics And Quality Management Fundamental Tools

Authors: Joseph Nguyen

1st Edition

B0CNGG3Y2W, 979-8862833232

More Books

Students also viewed these Databases questions

Question

Q.1. Taxonomic classification of peafowl, Tiger and cow ?

Answered: 1 week ago

Question

Q .1. Different ways of testing the present adulterants ?

Answered: 1 week ago

Question

Q.1. Health issues caused by adulteration data ?

Answered: 1 week ago

Question

5-8 What are the advantages and disadvantages of the BYOD movement?

Answered: 1 week ago