Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
while bill_amount < 0
puts "Please enter a positive number:"
puts bill_amount = gets.chomp.to_i
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