probem with calculation

Hi guys, I'm working on a school project and have come across a minor difficulty.
This program is supposed to represent a Vending machine and output various things which is all fine but what I'm having problems with is when purchasing a product the program needs to output the product bought and the change the user gets back, this is supposed to be in the switch statement. Any advice?? (let me know if you need more code)

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include<iostream>
#include<string>
#include<vector>

using namespace std;

#include"inventory.h"
#include"balance.h"
#include"draw.h"

int main()
{
	Balance s;
	Inventory i;
	Draw d;
	bool run = true;
	bool addlist = false;
	bool kvittosyns = false;
	string pname;
	int pprice = 0;
	char selection;
	string lastprod = "";
	bool vaxelsyns = false;
	int vaxel = 0;
mainmeny:
	vaxelsyns = false;

	i.addProduct(Product("Product1", 50));i.addProduct(Product("Product2", 10));
	i.addProduct(Product("Product3", 25));i.addProduct(Product("Product4", 95));
	i.addProduct(Product("Product5", 2));i.addProduct(Product("Product6", 15));
	i.addProduct(Product("Product7", 10));i.addProduct(Product("Product8", 7));
	
	do
	{
		system("cls");
		d.drawtop();
		i.callProduct();
		d.drawoption();
		d.drawsaldo(s.getbalance());
		d.drawmainoption();
		if(kvittosyns ==true)
		{
			d.kvitto(lastprod);
		}
		if(vaxelsyns == true)
		{
			d.drawvaxel(vaxel);
		}
		d.drawchoice();
		kvittosyns = false;
		vaxelsyns =false;
		int num;
		cin >> selection;
		
		switch(toupper(selection))
		{
		//case 1:
                //case 2:
                //case 3: etc.....Code to go here
		case 'A':
			s.change(10); 
			break;
		case 'B':
			s.change(5);
			break;
		case 'C':
			s.change(1);
			break;
		case 'V':
			goto addmeny;
			break;
		case 'P':
			vaxel = s.getbalance();
			s.change(-s.getbalance());
			vaxelsyns = true;
			break;
		case 'Q':
			run == false;
			return 0;
			break;
		}
	}while(run == true);
addmeny:
	if(run==true)
	{
		do
		{
			system("cls");
			d.drawtop();
			if(addlist==true)
			{
				i.callProduct();
			}
			d.drawaddopt();
			d.drawchoice();
			int choice;
			cin >> choice;
			cin.get();
			switch(choice)
			{
			case 0:
				addlist=false;
				goto mainmeny;
				break;
			case 1:
				system("cls");
				d.drawtop();
				cout <<  "Product name: ";
				getline(cin, pname);
				cout << "Product price: ";
				cin >> pprice;
				cin.get();
				i.addProduct(Product(pname, pprice));
				break;
			case 2:
				system("cls");
				i.callProduct();
				
				cout << "\n\nPress ENTER to continue";
				cin.get();
				break;
			}

		}while(run==true);
	}
}
What is the minor problem?
Sorry if I wasnt clear....the problem I'm having is if the user inputs 1....8 the program has to output ex: "You have purchased 'aProduct' and your change is 'change'." and then go back to the main menu.
Try making a function for the Menu and one for checking the Choice.
You can then call choice in Menu and menu in Choice (at the end of every case.)

This uses recursion and may not be the best way to do it, but it will work!

Ok, thanks will try this.
Topic archived. No new replies allowed.