Created
September 18, 2015 21:40
-
-
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.
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
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