-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_2.vb
208 lines (174 loc) · 8.42 KB
/
lab_2.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
Module lab_2
Sub main()
'2. Mini Calculator
Dim bool As Boolean = True
Dim bool2 As Boolean = True
Dim var1 As String, var2 As String
Dim input2 As String
While (bool)
Console.WriteLine("Please select a letter corresponding to an operation.")
Console.WriteLine()
Console.WriteLine(menu())
Dim input As String = Console.ReadLine()
'Checks the users input option for select menu
If (input.ToLower() = "a") Then
Console.WriteLine("Please select a number: ")
var1 = Console.ReadLine()
Console.WriteLine("Please select a second number: ")
var2 = Console.ReadLine()
If (IsNumeric(var1) And IsNumeric(var2)) Then
Console.WriteLine("Chosen operation (Addition) " & var1 & " + " & var2 & " = " & add(var1, var2))
'checks if user would like to continue
Console.WriteLine("would you like to continue?")
input2 = Console.ReadLine()
If (input2.ToLower() <> "yes") Then
Console.WriteLine("This program is terminated. Goodbye!")
bool = False
End If
Else
Console.WriteLine("Invalid entry. Your choices must be a number between 0 - 99")
End If
End If
If (input.ToLower() = "s") Then
Console.WriteLine("Please select a number: ")
var1 = Console.ReadLine()
Console.WriteLine("Please select a second number: ")
var2 = Console.ReadLine()
If (IsNumeric(var1) And IsNumeric(var2)) Then
Console.WriteLine("Chosen operation (Subtraction) " & var1 & " - " & var2 & " = " & subtract(var1, var2))
Console.WriteLine()
'checks if user would like to continue
Console.WriteLine("would you like to continue?")
input2 = Console.ReadLine()
If (input2.ToLower() <> "yes") Then
Console.WriteLine("This program is terminated. Goodbye!")
bool = False
End If
Else
Console.WriteLine("Invalid entry. Your choices must be a number between 0 - 99")
End If
End If
If (input.ToLower() = "m") Then
Console.WriteLine("Please select a number: ")
var1 = Console.ReadLine()
Console.WriteLine("Please select a second number: ")
var2 = Console.ReadLine()
If (IsNumeric(var1) And IsNumeric(var2)) Then
Console.WriteLine("Chosen operation (Multiplication) " & var1 & " * " & var2 & " = " & multiply(var1, var2))
Console.WriteLine()
'checks if user would like to continue
Console.WriteLine("would you like to continue?")
input2 = Console.ReadLine()
If (input2.ToLower() <> "yes") Then
Console.WriteLine("This program is terminated. Goodbye!")
bool = False
End If
Else
Console.WriteLine("Invalid entry. Your choices must be a number between 0 - 99")
End If
End If
If (input.ToLower() = "d") Then
Console.WriteLine("Please select a number: ")
var1 = Console.ReadLine()
Console.WriteLine("Please select a second number: ")
var2 = Console.ReadLine()
If (IsNumeric(var1) And IsNumeric(var2)) Then
Console.WriteLine("Chosen operation (Divide) " & var1 & " / " & var2 & " = " & divide(var1, var2))
Console.WriteLine()
'checks if user would like to continue
Console.WriteLine("would you like to continue?")
input2 = Console.ReadLine()
If (input2.ToLower() <> "yes") Then
Console.WriteLine("This program is terminated. Goodbye!")
bool = False
End If
Else
Console.WriteLine("Invalid entry. Your choices must be a number between 0 - 99")
End If
End If
If (input.ToLower() = "mod") Then
Console.WriteLine("Please select a number: ")
var1 = Console.ReadLine()
Console.WriteLine("Please select a second number: ")
var2 = Console.ReadLine()
If (IsNumeric(var1) And IsNumeric(var2)) Then
Console.WriteLine("Chosen operation (Modulo) " & var1 & " modulo " & var2 & " = " & modulo(var1, var2))
Console.WriteLine()
'checks if user would like to continue
Console.WriteLine("would you like to continue?")
input2 = Console.ReadLine()
If (input2.ToLower() <> "yes") Then
Console.WriteLine("This program is terminated. Goodbye!")
bool = False
End If
Else
Console.WriteLine("Invalid entry. Your choices must be a number between 0 - 99")
End If
End If
If (input.ToLower() = "ex") Then
Console.WriteLine("Please select a number: ")
var1 = Console.ReadLine()
Console.WriteLine("Please select a second number: ")
var2 = Console.ReadLine()
If (IsNumeric(var1) And IsNumeric(var2)) Then
Console.WriteLine("Chosen operation (Exponent) " & var1 & " ^ " & var2 & " = " & exponent(var1, var2))
Console.WriteLine()
'checks if user would like to continue
Console.WriteLine("would you like to continue?")
input2 = Console.ReadLine()
If (input2.ToLower() <> "yes") Then
Console.WriteLine("This program is terminated. Goodbye!")
bool = False
End If
Else
Console.WriteLine("Invalid entry. Your choices must be a number between 0 - 99")
End If
End If
If (input.ToLower() = "e") Then
Console.WriteLine("You have exited my crappy program. Goodbye!")
bool = False
End If
'validates if the user entered a letter thats does not match the menu provided
If (input.ToLower() <> "a" And input.ToLower() <> "s" And input.ToLower() <> "m" And input.ToLower() <> "d" And input.ToLower() <> "ex" And input.ToLower() <> "mod" And input.ToLower() <> "e") Then
Console.WriteLine("Clearly you're an incompetent moron who cannot read between the lines. Go away...")
bool = False
End If
End While
Console.Read()
End Sub
Function menu() As String
Dim menu_operators As String
menu_operators = "Add | A " & vbCrLf & "Subtract | S " & vbCrLf & "Multiply | M " & vbCrLf & "Divide | D " & vbCrLf & "Modulos | Mod " & vbCrLf & "Exponent | ex " & vbCrLf & "Exit | E"
Return menu_operators
End Function
Function add(num1 As Double, num2 As Double) As Double
Dim result As Double
result = num1 + num2
Return result
End Function
Function subtract(num1 As Double, num2 As Double) As Double
Dim result As Double
result = num1 - num2
Return result
End Function
Function multiply(num1 As Double, num2 As Double) As Double
Dim result As Double
result = num1 * num2
Return result
End Function
Function divide(num1 As Double, num2 As Double) As Double
Dim result As Double
result = num1 / num2
Return result
End Function
Function modulo(num1 As Double, num2 As Double) As Double
Dim result As Double
result = num1 Mod num2
Return result
End Function
Function exponent(num1 As Double, num2 As Double) As Double
Dim result As Double
result = num1 ^ num2
Return result
End Function
End Module