Skip to content

Instantly share code, notes, and snippets.

@rplugge
Created June 1, 2015 19:48
Show Gist options
  • Save rplugge/938586592e3ea3c5aeb2 to your computer and use it in GitHub Desktop.
Save rplugge/938586592e3ea3c5aeb2 to your computer and use it in GitHub Desktop.
Dinner Split
class Checksplitter
def initialize(total_cost, people_number, tip_percent)
@total_cost = total_cost.to_f
@people_number = people_number.to_i
@tip_percent = tip_percent.to_f
end
def people_number
@people_number
end
def tip
@total_cost * @tip_percent
end
def cost_person
before_split = @total_cost + tip
after_split = before_split / people_number
end
def output
puts "Dinner is $#{cost_person} per person."
end
end
puts "Let's give this a try"
puts "What was the cost of your dinner?"
a = gets.chomp
puts "How many people were there?"
b = gets.chomp
puts "What percentage would you like to tip? (Format = 0.25)"
c = gets.chomp
dinner = Checksplitter.new(a, b, c)
puts dinner.output
@rplugge
Copy link
Author

rplugge commented Jun 1, 2015

I'll add the rounding in, thanks for looking it over!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment