Skip to content

Instantly share code, notes, and snippets.

@Rosa-Fox
Created September 18, 2015 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rosa-Fox/9718154437d02ce0f39e to your computer and use it in GitHub Desktop.
Save Rosa-Fox/9718154437d02ce0f39e to your computer and use it in GitHub Desktop.
Script to print total cost of a bill with tip included. This is based on user input to the terminal.
puts "How much does the bill come to?"
bill_amount = gets.chomp.to_i
while bill_amount == 0
puts "Please enter a valid number for the bill amount:"
bill_amount = gets.chomp.to_i
end
while bill_amount < 0
puts "Please enter a positive number:"
puts bill_amount = gets.chomp.to_i
end
puts "The bill is £#{bill_amount}"
puts "What is the tip percentage?"
percentage = gets.chomp.to_f.ceil
puts "The tip is #{percentage}%."
tip = bill_amount / 100 * percentage
total = bill_amount + tip
puts "The total is £#{total}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment