Machine Problem Question C++

When i run on visual c++ express edition 2008 i receive warnings
what does this mean to my codes below?

1>c:\users\admin\desktop\basdfasdasd\basdfasdasd\basdfasdasd.cpp(14) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\admin\desktop\basdfasdasd\basdfasdasd\basdfasdasd.cpp(45) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\admin\desktop\basdfasdasd\basdfasdasd\basdfasdasd.cpp(52) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
and others similar...

Machine Problem
Drink Machine Simulator

Create a program that will display the list of drinks available and its prices and let the user choose which drink he/ she wishes to avail. After the user selects a drink the user must input the amount of money he/she will pay, then the program displays the amount of change. If the user selects a drink that has already sold out, the program must display a message regarding it. The user can buy as much drinks as they want until they decide to quit the program.

Requirements:
• Structure that has members for the name of the drink, price of the drink, and the number of availability
• Function that will initialize the contents of the structure
• Function that will compute for the change of the user


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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include<iostream>
#include<string>

using namespace std;

struct choose{
	string name;
	float price;
	float supply;
}Royal, Pepsi, Water, Coffee, Tea;
int change(float Money, float Price)
{
    int MChange;
    MChange=Money-Price;
    return MChange;
}
void input(float a,float b,float c,float d,float e,float f,float g,float h,float i,float j)
{
int Choose;
int Money;
char Choice;
    cout<<"                     The Product's Information are as follows:\n\n\n";
    cout<<"Brand Name ************************* Price ***************************** Supply ";
    cout<<"(1)"<<Royal.name<<"                            "<<f<<" Pesos                               "<<a<<endl;
    cout<<"(2)"<<Pepsi.name<<"                            "<<g<<" Pesos                               "<<b<<endl;
    cout<<"(3)"<<Water.name<<"                            "<<h<<" Pesos                               "<<c<<endl;
    cout<<"(4)"<<Coffee.name<<"                          "<<i<<" Pesos                               "<<d<<endl;
    cout<<"(5)"<<Tea.name<<"                             "<<j<<" Pesos                               "<<e<<endl;
    cout<<"\n\n\n\n\n\n\n\n\n\n\n";
    cout<<"Please choose your product(Product Number): ";
    cin>>Choose;
    if(Choose<1 || Choose>5)
        {
            cout << string(50, '\n');
            cout<<"Invalid input, please try again"<<endl<<endl;
				input(a,b,c,d,e,f,g,h,i,j);
        }
    cout<<endl;
    cout<<"Please input money: ";
    cin>>Money;
	cout<<endl;

	if(Choose==1)
    {
        if(a<0)
        {
        cout<<"Sorry there are no more stocks for that product, please try again "<<endl<<endl;
        }

		if (change(Money,f)<0)
        {
            cout << string(50, '\n');
            cout<<"Your money was not enough to complete the purchase, please try again "<<endl<<endl;
				input(a,b,c,d,e,f,g,h,i,j);
		}
		cout<<"You have purchased Royal"<<endl;
		cout<<"Your change is "<<change(Money,f)<<endl;
		cout<<"Do you want purchase again [y] to continue [n] to quit: ";
		cin>>Choice;
		cout<<endl;
    }
		if(Choice=='y' || Choice=='Y')
        {
                a--;
                 cout << string(50, '\n');
				input(a,b,c,d,e,f,g,h,i,j);
		}else
		{
        cout<<"Good Bye";
        }


	if(Choose==2)
    {
        if(b<0)
        {
        cout<<"Sorry there are no more stocks for that product, please try again "<<endl<<endl;
        }

		if (change(Money,g)<0)
        {
            cout << string(50, '\n');
            cout<<"Your money was not enough to complete purchase, please try again "<<endl<<endl;
				input(a,b,c,d,e,f,g,h,i,j);
		}
		cout<<"You have purchased Pepsi"<<endl;
		cout<<"Your change is "<<change(Money,g)<<endl;
		cout<<"Do you want purchase again [y] to continue [n] to quit: ";
		cin>>Choice;
		cout<<endl;
    }
		if(Choice=='y' || Choice=='Y')
		{
                b--;
                 cout << string(50, '\n');
				input(a,b,c,d,e,f,g,h,i,j);
		}else
		{

				cout<<"Good Bye";
        }

	if(Choose==3)
    {
        if(c<0)
        {
        cout<<"Sorry there are no more stocks for that product, please try again "<<endl<<endl;
        }
		if (change(Money,h)<0)
        {
            cout << string(50, '\n');
            cout<<"Your money was not enough to complete purchase, please try again "<<endl<<endl;
				input(a,b,c,d,e,f,g,h,i,j);
		}
		cout<<"You have purchased Water"<<endl;
        cout<<"Your change is "<<change(Money,h)<<endl;
		cout<<"Do you want purchase again [y] to continue [n] to quit: ";
		cin>>Choice;
		cout<<endl;
    }
		if(Choice=='y' || Choice=='Y')
		{
                c--;
                 cout << string(50, '\n');
				input(a,b,c,d,e,f,g,h,i,j);
		}else
		{

				cout<<"Good Bye";
        }


	if(Choose==4)
    {
        if(d<0)
        {
        cout<<"Sorry there are no more stocks for that product, please try again "<<endl<<endl;
        }
		if (change(Money,i)<0)
        {
            cout << string(50, '\n');
            cout<<"Your money was not enough to complete purchase, please try again "<<endl<<endl;
				input(a,b,c,d,e,f,g,h,i,j);
        }
		cout<<"You have purchased Coffee"<<endl;
		cout<<"Your change is "<<change(Money,i)<<endl;
		cout<<"Do you want purchase again [y] to continue [n] to quit: ";
		cin>>Choice;
		cout<<endl;
    }
		if(Choice=='y' || Choice=='Y')
		{
                d--;
                 cout << string(50, '\n');
				input(a,b,c,d,e,f,g,h,i,j);
		}else
		{

				cout<<"Good Bye";
        }


	if(Choose==5)
    {
        if(e<0)
        {
        cout<<"Sorry there are no more stocks for that product, please try again "<<endl<<endl;
        }
		if (change(Money,j)<0)
        {
            cout << string(50, '\n');
            cout<<"Your money was not enough to complete purchase, please try again "<<endl<<endl;
				input(a,b,c,d,e,f,g,h,i,j);
		}
		cout<<"You have purchased Tea"<<endl;
		cout<<"Your change is "<<change(Money,j)<<endl;
		cout<<"Do you want purchase again [y] to continue [n] to quit: ";
		cin>>Choice;
		cout<<endl;
    }
		if(Choice=='y' || Choice=='Y')
        {
                e--;
                 cout << string(50, '\n');
				input(a,b,c,d,e,f,g,h,i,j);
		}else
		{

				cout<<"Good Bye";
        }

}
int main ()
{
    Royal.name="Royal";
    Pepsi.name="Pepsi";
    Water.name="Water";
    Coffee.name="Coffee";
    Tea.name="Tea";

        Royal.supply=8.0;
		Pepsi.supply=6.0;
		Water.supply=10.0;
		Coffee.supply=5.0;
		Tea.supply=3.0;

		Royal.price=10.0;
		Pepsi.price=12.0;
		Water.price=20.0;
		Coffee.price=7.50;
		Tea.price=8.50;

		float a=Royal.supply;
		float b=Pepsi.supply;
		float c=Water.supply;
		float d=Coffee.supply;
		float e=Tea.supply;
		float f=Royal.price;
		float g=Pepsi.price;
		float h=Water.price;
		float i=Coffee.price;
		float j=Tea.price;

	cout<<"  ************Welcome to Zenon's Virtual Drink Machine Simulator!*************"<<endl;
	cout<<"                         [y] to continue  [n] to quit";
	char answer;
	cout<<"                                                                  ";
	cin>>answer;
    if (answer=='y' || answer=='Y')
    {
        cout << string(50, '\n');
        input(a,b,c,d,e,f,g,h,i,j);
    } else
    {
        cout << string(50, '\n');
        cout<<"                   Good Bye! Happy to see you again! :D";
    }



	return 0;
}

Last edited on
Hi, please use code tags for all of your code - http://www.cplusplus.com/articles/jEywvCM9/

Jeez mate, you have like 4 missing '}'. Remember all brackets need a closing one.

I made it run by adding 4 brackets above main, but Im not sure if that is how you want teh program structure to work -


1
2
3
4
5
6
          }    
        }
    }
}
int main() {
Last edited on
(Thank you for the code tags) beginner here sorry
Now i have a new problem When i run on visual c++ express edition 2008 i received warnings
what does this mean
Last edited on
Topic archived. No new replies allowed.