Create a program in C++ in Microsoft Visual Studio 2010 that simulates a vending
ID: 3538839 • Letter: C
Question
Create a program in C++ in Microsoft Visual Studio 2010 that simulates a vending machine. Allow the user to enter the price of the item in the vending machine. Assume that the prices of the items in the vending machine don't exceed 1 dollar. Assume the vending machine only takes single dollars. The output of your program is your change. Your change will be quarters, dimes and nickels only. Assume the price of an item is always a multiple of 5. The following is a possible dialogue with the user: Enter price of item: 45 You bought an item for 45 cents and gave me a dollar so your change is 2 quarters 0 dimes and 1 nickel Create a program in C++ in Microsoft Visual Studio 2010 that simulates a vending machine. Allow the user to enter the price of the item in the vending machine. Assume that the prices of the items in the vending machine don't exceed 1 dollar. Assume the vending machine only takes single dollars. The output of your program is your change. Your change will be quarters, dimes and nickels only. Assume the price of an item is always a multiple of 5. The following is a possible dialogue with the user: Enter price of item: 45 You bought an item for 45 cents and gave me a dollar so your change is 2 quarters 0 dimes and 1 nickelExplanation / Answer
//CODE TESTED IN MS VSIUAL STUDIO
#include <iostream>
#include <string>
using namespace std;
void computeCoin( int coinValue, int& number, int& amountLeft )
{
while(amountLeft>=coinValue)
{
amountLeft=amountLeft-coinValue;
number++;
}
}
int main() {
int coin,c2,q=0,d=0,n=0;
cout<<"Enter price of item:"<<endl;
cin >> coin;
if( (coin <1) || (coin>99) )
{ cout<<"Error : Price of item is not greater than dollar"<<endl; }
else
{
c2=coin;
coin=100-coin;
computeCoin(25, q, coin);
computeCoin(10, d, coin);
computeCoin(5, n, coin);
cout<<"You bought an item for "<<c2<<" and gave me a dollar so your change is: "<<endl;
cout<<q<<" quarter(s), "<<d<<" dime(s), and "<<n<<" nickel "<<endl;
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.