-
Notifications
You must be signed in to change notification settings - Fork 0
/
question1.vb
220 lines (169 loc) · 6.99 KB
/
question1.vb
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
Module question1
Sub main()
'Dim arr1(3) As String
'Dim input_item As String
'Dim input_price As String
'arr1(0) = "item 1"
'arr1(1) = "item 2"
'arr1(2) = "item 3"
'arr1(3) = "item 4"
'While (True)
' Console.WriteLine("Enter the new item.")
' input_item = Console.ReadLine()
' Console.WriteLine("Enter the items price.")
' input_price = Console.ReadLine()
'ReDim Preserve arr1(arr1.Length)
'input_item += input_price
'arr1(arr1.Length - 1) = input_item
' For i = 0 To arr1.Length - 1
' Console.WriteLine(arr1(i))
' Next
'End While
'arr2 = {{"item 0", "5.99", "5"}, {"item 1", "7.99", "50"}, {"item 2", "3.99", "7"}, {"item 3", "9.99", "80"}}
'---------------------------------------------------------------------------------------------------------------------
'2D array(limited rows)
Dim input_item As String
Dim input_price As String
Dim input_stock As String
Dim count As Integer = 4
Dim arr2(8, 2) As String
Dim check As Boolean = True
Dim bool2 As Boolean = True
While (check)
If (count <= 8) Then
While (input_item <> "0" And input_price <> "0" And input_stock <> "0")
Dim bool As Boolean = True
Do While (bool)
arr2(0, 0) = "Kebab"
arr2(0, 1) = "9.99"
arr2(0, 2) = "5"
arr2(1, 0) = "Beef"
arr2(1, 1) = "6.99"
arr2(1, 2) = "7"
arr2(2, 0) = "Chicken"
arr2(2, 1) = "4.00"
arr2(2, 2) = "9"
arr2(3, 0) = "Beer"
arr2(3, 1) = "0.99"
arr2(3, 2) = "10"
'Displays the menu
Console.WriteLine("menu items and prices below: " & vbNewLine)
For i = 0 To arr2.GetUpperBound(0)
For j = 0 To arr2.GetUpperBound(1)
Console.Write(arr2(i, j) & " ")
Next
Console.WriteLine()
Next
bool = False
Loop
Exit While
End While
'Requesting input for new items from the user
Console.WriteLine("Enter the new item.")
input_item = Console.ReadLine()
Console.WriteLine("Enter the items price.")
input_price = Console.ReadLine()
Console.WriteLine("Enter the items stock level.")
input_stock = Console.ReadLine()
If (input_item = "" Or IsNumeric(input_item) = True Or IsNumeric(input_price) = False Or IsNumeric(input_stock) = False) Then
Console.WriteLine("Invalid entry. Do your job jackass")
input_item = "0"
input_price = "0"
input_stock = "0"
Else
bool2 = False
'Adding users input items into the 2d array
arr2(count, 0) = input_item
arr2(count, 1) = input_price
arr2(count, 2) = input_stock
count += 1
End If
'Reaching the maximum number of items in the menu triggers a warning
Else
'Displays the menu
Console.WriteLine("menu items and prices below: " & vbNewLine)
For i = 0 To arr2.GetUpperBound(0)
For j = 0 To arr2.GetUpperBound(1)
Console.Write(arr2(i, j) & " ")
Next
Console.WriteLine()
Next
Console.WriteLine("You have reached the maximum capacity for entering items.")
check = False
End If
End While
'--------------------------------------------------------------------------------------------------------------------
'Dim arr(2, 4) As String
'Dim input_item As String
'Dim input_price As String
'Dim input_stock As String
'Dim bool As Boolean = True
'Dim count = 4
'arr(0, 0) = "Beer"
'arr(1, 0) = "6.99"
'arr(2, 0) = "5"
'arr(0, 1) = "Cheese"
'arr(1, 1) = "4.99"
'arr(2, 1) = "10"
'arr(0, 2) = "Candy"
'arr(1, 2) = "9.90"
'arr(2, 2) = "50"
'arr(0, 3) = "sugar"
'arr(1, 3) = "12.99"
'arr(2, 3) = "2"
'arr(0, 4) = "pickles"
'arr(1, 4) = "0.99"
'arr(2, 4) = "12"
'Console.WriteLine("||===== Menu =====||")
'Console.WriteLine()
'For x = 0 To arr.GetUpperBound(1)
' For y = 0 To arr.GetUpperBound(0)
' Console.Write(arr(y, x) & " ")
' Next
' Console.WriteLine()
'Next
'While (bool)
' Console.WriteLine("-------------------------")
' Console.WriteLine("Please enter a new item: ")
' input_item = Console.ReadLine()
' Console.WriteLine("Please enter the item's price: ")
' input_price = Console.ReadLine()
' Console.WriteLine("Please enter the total in stock: ")
' input_stock = Console.ReadLine()
' If (IsNumeric(input_item) = True Or input_item = "" Or IsNumeric(input_price) = False Or input_price = "" Or IsNumeric(input_stock) = False Or input_stock = "") Then
' Console.WriteLine("Invalid entry. Please try again...")
' Else
' ReDim Preserve arr(2, count + 1)
' arr(0, 0) = "Beer"
' arr(1, 0) = "6.99"
' arr(2, 0) = "5"
' arr(0, 1) = "Cheese"
' arr(1, 1) = "4.99"
' arr(2, 1) = "10"
' arr(0, 2) = "Candy"
' arr(1, 2) = "9.90"
' arr(2, 2) = "50"
' arr(0, 3) = "sugar"
' arr(1, 3) = "12.99"
' arr(2, 3) = "2"
' arr(0, 4) = "pickles"
' arr(1, 4) = "0.99"
' arr(2, 4) = "12"
' arr(0, count) = input_item
' arr(1, count) = input_price
' arr(2, count) = input_stock
' count += 1
' End If
' Console.WriteLine()
' Console.WriteLine("||===== Menu =====||")
' Console.WriteLine()
' For x = 0 To arr.GetUpperBound(1)
' For y = 0 To arr.GetUpperBound(0)
' Console.Write(arr(y, x) & " ")
' Next
' Console.WriteLine()
' Next
'End While
Console.Read()
End Sub
End Module