-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.rb
52 lines (45 loc) · 889 Bytes
/
calc.rb
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
def addition(n, m)
return n + m
end
def subtraction(n, m)
return n - m
end
def multiplication(n, m)
return n * m
end
def division(n, m)
if m == 0
puts "You can't divide by zero."
end
return n / m
end
def interface()
puts "Please enter a first number: "
num = gets.to_i
puts "Please enter a second number: "
snum = gets.to_i
puts "Please choose operation [+][-][*][/]: "
op = gets.chomp
calculator(num, snum, op)
end
def calculator (n, m, o)
if o == "+"
puts addition(n, m)
elsif o == "-"
puts subtraction(n, m)
elsif o == "*"
puts multiplication(n, m)
elsif o == "/"
puts division(n, m)
else
puts "Please choose a valid operation."
end
puts "Would you like to perform another operation? Y/N"
rstrt = gets.chomp.downcase
if rstrt == "y"
interface()
else
puts "Come back soon!"
end
end
interface()