Vending machine program

In this lab task, you have to create a program which simulates the process of Aruba Vending Machine placed in PAF-IAST Main block. First, set/initialize both coins of 5 rupees and 10 rupees in your program (i.e, how many coins are there in the machine at first that can be used for returning bills). Then take a user input in rupees, it should be in a multiple of 5 or 10 and not less than 0 and not greater than 100. Then provide with a menu of items, your machine has.

ID Name Price
100 Lays Rs. 20
101 Pepsi Rs. 50
.
.
So on

You must create an array of structure items (id, name, price, quantity).

Then when a user enters a correct id against an item it should decrement the quantity of that item and deduct the price from the user entered price. And asks whether user wants to buy more otherwise return remaining amount.

In case, user enter a wrong id, display an error message and say try again.

There must be an option for exiting, if user don’t want to buy anything.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <stdlib.h>
using namespace std;
struct Machine
{
	int id[5] = { 100,101,102,103,104 };
	string name[5] = {"Lays", "Pepsi","Fanta","Oreo","Sooper" };
	float price[5] = { 20,50,50,15,15 };
	float quantity[5] = { 10,10,10,10,10 };
};
void compareID()
{
	Machine p1;
	int ID;
	if (ID != p1.id[0] || ID != p1.id[1] || ID != p1.id[2] || ID != p1.id[3] || ID != p1.id[4])
	{
		cout << "ID not available. Please insert correct ID." << endl;
		
	}
	
}

int main()
{
	Machine p1;
	int Rs5coin = 100;
	int Rs10coin = 50;
	int bill;
	cout << "Welcome to Aruba vending machine."<<endl;
	cout << "ID  Name  Price  Quantity" << endl;
	cout << "100 Lays   20       10" << endl;
	cout << "101 Pepsi  50       10" << endl;
	cout << "102 Fanta  50       10" << endl;
	cout << "103 Oreo   15       10" << endl;
	cout << "104 Sooper 15       10" << endl;
	cout << "Insert Bill Amount: ";
	cin >> bill;
	if (bill > 100 || bill < 0)
	{
		cout << "Wrong bill inserted!!!(must be less than 100 and greater than 0)" << endl;
	}
	if (bill % 5 != 0 || bill % 10 != 0)

	{
		cout << "wrong bill inserted!!(must be multiple of 5 or 10)" << endl;
	}
}
Topic archived. No new replies allowed.