ex21
This commit is contained in:
parent
aa308911d4
commit
fbb5e7e697
35
ex21.rb
Normal file
35
ex21.rb
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
def add(a, b)
|
||||||
|
puts "ADDING #{a} + #{b}"
|
||||||
|
a + b
|
||||||
|
end
|
||||||
|
|
||||||
|
def subtract(a, b)
|
||||||
|
puts "SUBTRACTING #{a} - #{b}"
|
||||||
|
a - b
|
||||||
|
end
|
||||||
|
|
||||||
|
def multiply(a, b)
|
||||||
|
puts "MULTIPLYING #{a} * #{b}"
|
||||||
|
a * b
|
||||||
|
end
|
||||||
|
|
||||||
|
def divide(a, b)
|
||||||
|
puts "DIVIDING #{a} / #{b}"
|
||||||
|
a / b
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Let's do some math with just functions!"
|
||||||
|
|
||||||
|
age = add(30, 5)
|
||||||
|
height = subtract(78, 4)
|
||||||
|
weight = multiply(90, 2)
|
||||||
|
iq = divide(100, 2)
|
||||||
|
|
||||||
|
puts "Age: #{age}, Height: #{height}, Weight: #{weight}, IQ: #{iq}"
|
||||||
|
|
||||||
|
# A puzzle for the extra credit, type it in anyway.
|
||||||
|
puts "Here is a puzzle."
|
||||||
|
|
||||||
|
what = add(age, subtract(height, multiply(weight, divide(iq, 2))))
|
||||||
|
|
||||||
|
puts "That becomes: #{what} Can you do it by hand?"
|
Loading…
Reference in New Issue
Block a user