Subject Computer Science C-Family Programming

Question

Vending Machine Program

Program Specifications/Requirements.

• Create a C++ program that simulates a vending machine.

• The vending machine holds six items numbered 1 through 6. The cost of each item is as follows:

Item# Cost
1       $1.50
2       $.75
3       $.90
4       $.75
5       $1.25
6       $.75

• When the program runs, a menu will appear showing the user the options they have to purchase (item # and cost).

• Allow the user to enter two inputs. (Note: You may ask for these on separate lines).

o The item number desired.
o The amount of money they are depositing into the vending machine.

• Your program should include input validation to check to make sure that the input is the following. Display an error message and ask for the input again if the input does not meet these conditions.

o Ensure the item # is a value of 1 through 6.
o Ensure cost entered is at greater than 0 and less than or equal to 10.
o Extra credit #1: Ensure item # an integer (not a float or string).
o Extra credit #2: Ensure cost is an integer or float (not a string).

• The following information should be displayed to the user once an item and an amount of money has been entered:

• Display the following if the money entered was sufficient for the item selected (format all money/currency with $ before and two digits to right of decimal place):

Thank you for purchasing item # 5. Your change is $ 3.50

If the amount of money entered was the exact amount, the following similar message would be displayed.

Thank you for purchasing item # 5. Your change is $ 0.00

• If the money entered was insufficient, your program should display a message indicating the money entered was insufficient, how much additional money needs to be entered, and continue to ask for an additional amount of money until enough money has been entered to purchase the selected item.

Please enter an additional $.50

• Give the customer the option to choose another item to purchase or to quit (Y or N).
o Extra Credit #3: ensure input entered is Y, Yes, YES, y, N, No, NO, or N. If not, display an error message and require the user enter another response.

• Each customer can only purchase a maximum of three items. The program will automatically quit after the third purchase.

• When the programs ends (i.e. the user indicates they do not want to make another purchase or they have completed purchasing their third item), the following summary information is displayed:

Number of items purchased: 2
Total cost of all items purchased: $2.75
Total amount of money inserted: $5.00
Total amount of change returned: $2.25

• You must use at least one user-defined module/function in a meaningful way appropriate to the program. It is up to you whether you want to use lists/arrays.

Sample Program Run #1
======================
|   Vending Machine          |
======================
Item # Cost
------ -----
1       $1.50
2       $0.75
3       $0.90
4       $0.75
5       $1.75
6       $0.75
----------------------------------
Enter the item number you want (1-6): 1

Enter your money amount (e.g. 1.5 for $1.50, .50 for $0.50, etc.): 11
Invalid $ amount. Enter your money amount (e.g. 1.5 for $1.50, .50 for $0.50, etc.): 10
Thank you for purchasing item # 1. Your change is $8.50

Do you want to make another purchase (Y or N)? n

          Purchase Summary
------------------------------------------
Number of items purchased: 1
Total cost of all items purchased: $1.50
Total amount of money inserted: $10.00
Total amount of change returned: $8.50

Sample Program Run #2
======================
|   Vending Machine          |
======================
Item # Cost
------ -----
1       $1.50
2       $0.75
3       $0.90
4       $0.75
5       $1.75
6       $0.75
----------------------------------
Enter the item number you want (1-6): 7
Invalid item choice. Enter valid item number (1-6): dddddd
Invalid item choice. Enter valid item number (1-6): 1

Enter your money amount (e.g. 1.5 for $1.50, .50 for $0.50, etc.): .5
Please enter an additional $1.00
Enter your money amount (e.g. 1.5 for $1.50, .50 for $0.50, etc.): 1
Thank you for purchasing item #1. Your change is: $0.00.

Do you want to make another purchase (Y or N)? y
======================
|   Vending Machine         |
======================
Item # Cost
------ -----
1       $1.50
2       $0.75
3       $0.90
4       $0.75
5       $1.75
6       $0.75
----------------------------------
Enter the item number you want (1-6): 2

Enter your money amount (e.g. 1.5 for $1.50, .50 for $0.50, etc.): 3
Thank you for purchasing item # 2. Your change is $2.25

Do you want to make another purchase (Y or N)? y
======================
|   Vending Machine         |
======================
Item # Cost
------ -----
1       $1.50
2       $0.75
3       $0.90
4       $0.75
5       $1.75
6       $0.75
----------------------------------
Enter the item number you want (1-6): 3

Enter your money amount (e.g. 1.5 for $1.50, .50 for $0.50, etc.): .9
Thank you for purchasing item #3. Your change is: $0.00.

Thank you. You have reached your maximum number of purchases (3).

          Purchase Summary
------------------------------------------
Number of items purchased: 3
Total cost of all items purchased: $3.15
Total amount of money inserted: $5.40
Total amount of change returned: $2.25


Sample Program Run #3
======================
|   Vending Machine          |
======================
Item # Cost
------ -----
1       $1.50
2       $0.75
3       $0.90
4       $0.75
5       $1.75
6       $0.75
------------------------------
Enter the item number you want (1-6): 1

Enter your money amount (e.g. 1.5 for $1.50, .50 for $0.50, etc.): .5
Please enter an additional $1.00
Enter your money amount (e.g. 1.5 for $1.50, .50 for $0.50, etc.): .5
Please enter an additional $0.50
Enter your money amount (e.g. 1.5 for $1.50, .50 for $0.50, etc.): 1
Thank you for purchasing item # 1 . Your change is $0.50

Do you want to make another purchase (Y or N)? n

          Purchase Summary
------------------------------------------
Number of items purchased: 1
Total cost of all items purchased: $1.50
Total amount of money inserted: $2.00
Total amount of change returned: $0.50

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

using namespace std;

int numbers_only(const char *s);
int alphabet_only(const char *s);
void purchaseSummary(int count, double totalpurchased, double totalmoney, double totalreturned);

int main(void)
{

double prodPrice[] = { 1.5,0.75,0.90,0.75,1.75,0.75 };

char input[20], breakoutlerloop, breakoutermostloop = 0;
double money, totalmoney = 0, totalpurchased = 0, totalreturned = 0;
int count = 0, choice = 0;

while (count < 3 && breakoutermostloop == 0)
{

cout << "== == == == == == == == == == ==\n";...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$35.00

or free if you
register a new account!

Related Homework Solutions

Get help from a qualified tutor
Live Chats