Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Coffee vending machine provides coffee in three sizes: small (9oz), medium (12oz), and large (15oz). Write a program to determine the drink size based

The Coffee vending machine provides coffee in three sizes: small (9oz), medium (12oz), and large (15oz). Write a program to determine the drink size based on the letter the user enters. Print a message to the user giving the various drink size options and then prompt the user for the drink size. The user can enter an 's' or 'S' for small, an 'm' or 'M' for medium, and an '1' or 'L' for large. Depending on which size the user requests, print a message such as: "You have ordered a (small, medium, large) drink." In addition to displaying the size ordered, also record a price multiplier. The price multiplier for a small is 1, for a medium is 2, and for a large is 3. If the user does not enter a valid character, print an error message (such as "Error: Invalid drink size") and exit the program. You should use nested if-then-else statements for this problem. After the nested if-then-else statements, print the value of the price multiplier to ensure that the correct value was recorded (the price multiplier will be used in program 4). Hint: use the logical OR expression in your comparisons. A flow chart algorithm for each program The program (source code - CPP code) - Don't forget to include your header comments, any other useful comments, and to indent properly. Screen captures showing that the program executed properly for each test case you are responsible for determining the number of test cases required to adequately demonstrate that your program works) In this assignment you will write four programs related to the user interface for a beverage vending machine. In the first three programs you will write subsystems of the interface and in the fourth program you will combine your first three programs to create the complete interface. You can decide the types of products that your vending machine sells and the prices for each product (provided that they meet the general guidelines). How to handle incorrect inputs: Whenever you have an interface where a user can enter any value (not simply push a button), there is a chance that they may enter an invalid value. In this case, your program should check for invalid values and display an error message to the user and exit the program. There is a function exit() that is used in C to exit the program. The function exit() is provided in the standard library and it expects one argument that is an integer value. A value of O indicates to the Operating System (OS) that the program exited normally and a non-zero value indicates that an error has occurred. The standard library defines two constants that you can use in your programs: EXIT_FAILUE which is set to one in the stdlib.h header file (#define EXIT_FAILURE 1) and EXIT_SUCCESS which is set to zero in the stdlib.h header (#define EXIT_SUCCESS 0). So, to exit your programs in this assignment (in the case an error occurs and your program needs to exit before reaching the return 0 statement), make sure to: 1) include the stdlib.h header file (put "#include ") at the top of your file, and 2) after printing an error message, call the exit function when an error occurs (use "error(EXIT_FAILURE);"). Note, don't include the quotes

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

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

Evaluate the following integrals. [x In x dx

Answered: 1 week ago

Question

Be aware of your speaking rate, and adjust it if necessary.

Answered: 1 week ago