Write a C++ program that operates as a vending machine. The vending machine shou
ID: 3553298 • Letter: W
Question
Write a C++ program that operates as a vending machine. The vending machine should display four snack choices to the user (cookie, chip, candy, and soda). Your program should replace each of the snack choices with your favorite type of related snack. For example, chip could be replaced by Cheetos and candy could be replaced by Snickers. Be creative! This program should include a combination of void and value-returning functions. In particular, use five separate functions to do the following:
1. Create a value-returning function that displays the snack choices and prompts the user to select one (For example, Please make a selection. Press 1 for M&M Cookies. Press 2 for Cheetos. Press 3 for Snickers. Press 4 for Mountain Dew). Use an appropriate message to ask the user to enter a number.
2. Create four void functions that display the snack that corresponds with the user
Explanation / Answer
this can be an expected program..
#include<iostream.h>
int snack();
void unclechips();
void britannia();
void snowman();
void pepsi();
void main()
{
int n;
cout<<"welcome to snacks centre";
n=snack();
if(n==1)
{
unclechips();
elseif(n==2)
{
britannia();
}
elseif(n==3)
{
snowman();
}
elseif(n==4)
{
pepsi();
}
}
else
{
cout<<"invalid entry.your money is being returned";
}
cout<<"thank you";
}
int snack()
{
int x;
cout<<"1.uncle chips/n2.britannia cookies/n3.snowman candy/n4.pepsi(coke)";
cout<<"please enter your choice:";
cin>>x;
return(x);
}
void unclechips()
{
cout<<"you have selected uncle chips/n plz enter cash to enjoy the taste";
}
void britannia()
{
cout<<"you have selected britannia cookies/n plz enter cash to enjoy the taste";
}
void snowman()
{
cout<<"you have selected snowman candy/n plz enter cash to enjoy the taste";
}
void pepsi()
{
cout<<"you have selected pepsi coke/n plz enter cash to enjoy the taste";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.