-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.rb
48 lines (42 loc) · 1.03 KB
/
calculator.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
def add
puts "Which numbers would you like to add?"
in1 = gets.chomp.to_i
in2 = gets.chomp.to_i
sum = in1 + in2
puts "The sum is... #{sum}"
end
def subtract
puts "Which numbers would you like to subtract?"
in1 = gets.chomp.to_i
in2 = gets.chomp.to_i
diff = in1 - in2
puts "The difference is... #{diff}"
end
def multiply
puts "Which numbers would you like to multiply?"
in1 = gets.chomp.to_i
in2 = gets.chomp.to_i
prod = in1 * in2
puts "The product is... #{prod}"
end
def divide
puts "Which numbers would you like to divide?"
in1 = gets.chomp.to_i
in2 = gets.chomp.to_i
quot = in1 / in2
puts "The quotient is... #{quot}"
end
def modulus
in1 % in2
end
puts "Would you like to [add], [subtract], [multiply] or [divide]?"
response = gets.chomp
if response == "add" then
add
elsif response == "subtract" then
subtract
elsif response == "multiply" then
multiply
elsif response == "divide" then
divide
end