Created
June 1, 2015 19:48
-
-
Save rplugge/938586592e3ea3c5aeb2 to your computer and use it in GitHub Desktop.
Dinner Split
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'll add the rounding in, thanks for looking it over!