Skip to content

Instantly share code, notes, and snippets.

@malisbad
Last active September 3, 2015 06:59
Show Gist options
  • Save malisbad/f0dedfba7ccb49115db3 to your computer and use it in GitHub Desktop.
Save malisbad/f0dedfba7ccb49115db3 to your computer and use it in GitHub Desktop.
def square_foot_cost(length, width)
sq_ft = length * width
sq_ft_rate = 15
sq_ft_rate * sq_ft
end
def colour_cost(num_colours) #you can customize the rates here for colours
colour_rate = 10
additional_colour_rate = 15
if num_colours <= 2
colour_rate * num_colours
else
colour_rate*2 + (num_colours-2)*additional_colour_rate
end
end
def total(length, width, num_colours)
tax_rate = 15 # change the tax rate here
(square_foot_cost(length, width) + colour_cost(num_colours))*(tax_rate/100.00+1)
end
def signshop
puts "="*40 + "\n"
puts "Welcome to the sign shop!"
puts "We charge $15/sq.ft."
puts "=< 2 colours is $10/colour, $15 for each additional colour"
puts "We add 15% GST\n\n"
puts "Length?"
input = gets.chomp
length = Float(input)
puts "Width?"
input = gets.chomp
width = Float(input)
puts "How many colours?"
input = gets.chomp
num_colours = Integer(input)
puts "="*40
total = (total(length, width, num_colours)).round(2)
total = total.to_s #this if statement ensures that the total always has two decimal places
if /\d+\.\d$/.match(total)
total = total + "0"
end
puts "Your total is $#{total}"
end
signshop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment