cola machine

hello. im having a problem. this program is supposed to take the specific input from user and then display it. but unfortunately in the last part there is a problem.. it prints all the options.. although it is supposed to print 1... eg taking choice 1 and size 1 and printing only one out put... secondly in the last part when 1 is entered it starts again and when 2 is entered it closes down... thank you
And if i could get the amendments quickly that would be great.. i have to submit it in 8 hours.
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
  #include <iostream>
#include <string>
using namespace std;
int main()
{
	int choice;
	int size;
	int confirm;
	int ending;
	cout<<"COLA Machine"<<endl;
	cout<<"Welcome\nPlease Choose Your Drink"<<endl;
	cout<<"For Coca Cola Press 1"<<endl;
	cout<<"For Sprite Press 2"<<endl;
	cout<<"For Fanta Press 3"<<endl;
	cout<<"For Sprite 3G Press 4"<<endl;
	cout<<"For Diet Coke Press 5"<<endl;
	cout<<"For Sprite Zero Press 6"<<endl;
	cin>>choice;
	if (choice == 1)
	{
		cout<<"You have chosen Coca Cola"<<endl;
	}
	if (choice == 2)
	{
		cout<<"You have chosen Sprite"<<endl;
	}
	if (choice == 3)
	{
		cout<<"You have chosen Fanta"<<endl;
	}
	if (choice == 4)
	{
		cout<<"You have chosen Sprite 3G"<<endl;
	}
	if (choice == 5)
	{
		cout<<"You have chosen Diet Coke"<<endl;
	}
	if (choice == 6)
	{
		cout<<"You have chosen Sprite Zero"<<endl;
	}

	cout<<"Please select your Drink Size"<<endl;
	cout<<"For 300 ml Bottle Press 1"<<endl;
	cout<<"For 330 ml Can Press 2"<<endl;
	cout<<"For 500 ml Bottle Press 3"<<endl;
	cin>>size;
	if (size == 1)
	{
		cout<<"You have Selected 300 ml Bottle"<<endl;
	}
	if (size == 2)
	{
		cout<<"You have Selected 330 ml Can"<<endl;
	}
	if (size == 3)
	{
		cout<<"You have Selected 500 ml Bottle"<<endl;
	}

	if (choice == 1 || size == 1)
	{
		cout<<"You have chosen 300 ml Bottle of Coca Cola"<<endl;
	}
	if (choice == 2 || size == 1)
	{
		cout<<"You have chosen 300 ml Bottle of Sprite"<<endl;
	}
	if (choice == 3 || size == 1)
	{
		cout<<"You have chosen 300 ml Bottle of Fanta"<<endl;
	}
	if (choice == 4 || size == 1)
	{
		cout<<"You have chosen 300 ml Bottle of Sprite 3G"<<endl;
	}
	if (choice == 5 || size == 1)
	{
		cout<<"You have chosen 300 ml Bottle of Diet Coke"<<endl;
	}
	if (choice == 6 || size == 1)
	{
		cout<<"You have chosen 300 ml Bottle of Sprite Zero"<<endl;
	}
	if (choice == 1 || size == 2)
	{
		cout<<"You have chosen 330 ml Can of Coca Cola"<<endl;
	}
	if (choice == 2 || size == 2)
	{
		cout<<"You have chosen 330 ml Can of Sprite"<<endl;
	}
	if (choice == 3 || size == 2)
	{
		cout<<"You have chosen 330 ml Can of Fanta"<<endl;
	}
	if (choice == 4 || size == 2)
	{
		cout<<"You have chosen 330 ml Can of Sprite 3G"<<endl;
	}
	if (choice == 5 || size == 2)
	{
		cout<<"You have chosen 330 ml Can of Diet Coke"<<endl;
	}
	if (choice == 6 || size == 2)
	{
		cout<<"You have chosen 330 ml Can of Sprite Zero"<<endl;
	}
	if (choice == 1 || size == 3)
	{
		cout<<"You have chosen 500 ml Bottle of Coca Cola"<<endl;
	}
	if (choice == 2 || size == 3)
	{
		cout<<"You have chosen 500 ml Bottle of Sprite"<<endl;
	}
	if (choice == 3 || size == 3)
	{
		cout<<"You have chosen 500 ml Bottle of Fanta"<<endl;
	}
	if (choice == 4 || size == 3)
	{
		cout<<"You have chosen 500 ml Bottle of Sprite 3G"<<endl;
	}
	if (choice == 5 || size == 3)
	{
		cout<<"You have chosen 500 ml Bottle of Diet Coke"<<endl;
	}
	if (choice == 6 || size == 3)
	{
		cout<<"You have chosen 500 ml Bottle of Sprite Zero"<<endl;
	}
	cout<<"Do You Want to confirm"<<endl;
	cout<<"Press 1 to confirm OR 2 to reset"<<endl;
	cin>>confirm;
	if (confirm == 1)
	{
		cout<<"Here is your Drink. Enjoy!"<<endl;
	}
	if (confirm == 2)
	{
		cout<<"Do you Want to Reset or Quit\n Press 1 to Reset OR Press 2 to Quit"<<endl;
		cin>>ending;
	}
	if (ending == 1)
	{
		????????????
	}
	if (ending == 2)
		??????????
	return 0;
}
if (choice == 1 || size == 1)
it reads as if (choice == 1 or size == 1).
You want and (&&) here
okay... thanks and how do i go from one line to another.... like in the last 10 lines....
By making a while loop:
1
2
3
4
5
6
7
bool run = true;
while(run) {
    //Code
    std::string input;
    std::cin >> input;
    run = (input == "Again");
}
This code will ask in the end for a word. If this word is Again, it runs again.
sorry but im new t this... where am i supposed to insert this code?
Last edited on
Put the code you want repeated at line 3 in MiNiPaa's snippet.

Topic archived. No new replies allowed.