-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.exs
47 lines (38 loc) · 900 Bytes
/
12.exs
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
#calculate num gallons per square feet to paint a room
# 1 gal = 350 sq feet
defmodule Paint do
def calculate(length, width) do
area = length * width
output({div(area, gallon), rem(area, gallon)})
end
def output({gallons, 0}) do
IO.puts("You'll need #{gallons} gallons.")
end
def output({gallons, _}) do
IO.puts("You'll need #{gallons + 1} gallons.")
end
def gallon do
350
end
def handle_input(:error, string) do
prompt(string)
end
def handle_input({number, ""}, _string) do
number
end
def handle_input(_, string) do
prompt(string)
end
def prompt(string) do
string
|>IO.gets
|>String.strip
|>Integer.parse
|>handle_input(string)
end
end
length = Paint.prompt("What is the length of the room? ")
width = Paint.prompt("What is the width of the room? ")
Paint.calculate(length, width)
#divide by 350
#round up