-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.rb
More file actions
32 lines (31 loc) · 921 Bytes
/
calculator.rb
File metadata and controls
32 lines (31 loc) · 921 Bytes
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
#CALCULATOR
def calc
puts "Hello there!! I have built a simple calculator: "
puts "You are required to give me two numbers and an arithmetic operation"
puts "Enter your first number: "
number1 = gets.chomp()
puts "Enter a second number: "
number2 = gets.chomp()
puts "What do you want to do with the two numbers?"
puts "A. ADD"
puts "B. SUBTRACT"
puts "C. MULTIPLY"
puts "D. DIVIDE"
operation = gets.chomp()
if operation == "A"
add = number1.to_i + number2.to_i
puts add
elsif operation == "B"
subt = number1.to_i - number2.to_i
puts subt
elsif operation == "C"
multi = number1.to_i * number2.to_i
puts multi
elsif operation == "D"
divide = number1.to_i / number2.to_i
puts divide
else
puts "Cannot perform the arithmetic operation"
end
end
calc