Skip to content

Instantly share code, notes, and snippets.

@jamesmichiemo
Created June 9, 2013 01:48
Show Gist options
  • Save jamesmichiemo/5737281 to your computer and use it in GitHub Desktop.
Save jamesmichiemo/5737281 to your computer and use it in GitHub Desktop.
expressions in Ruby Language
# Discount exercise
# Calculate the discounted price for an item
#
print "What is the name of the item you would like to buy? "
itemDescription = gets.chomp()
print "What is the price of one #{itemDescription}? "
price = gets.chomp().to_f
print "At what percent is the discount offered? "
priceDiscount = gets.chomp().to_i
print "At what percent is the sales tax for purchases? "
salesTax = gets.chomp().to_f
taxTotal = (price - (price * (priceDiscount * 0.01)) + (price * salesTax * 0.01));
priceTotal = price - (price * (priceDiscount * 0.01));
puts "Your #{itemDescription} was originally priced at $#{price}, but after a #{priceDiscount}% discount, it is now $#{priceTotal} without tax, and $#{taxTotal} with tax."·
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment