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 |
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
Here's where attr_reader comes in handy. instead of having 8-10, all you would need to write between lines 1 & 2 is:
attr_reader :people_number
Your code looks precise and legible! Very easy to follow the program's instructions in the console.
One last thing, I would try and round it to make sure the final output isn't "Dinner is $8.799999999999999 per person."