这是我的代码:
print('What amount would you like to calculate tax for? ')
subtotal = gets.chomp
taxrate = 0.078
tax = subtotal * taxrate
puts "Tax on $#{subtotal} is $#{tax}, so the grand total is $#{subtotal + tax}."
第一个输出:What amount would you like to calculate tax for?
输入:100
。
最终输出:Tax on $100 is $, so the grand total is $100.
我相信我应该得到一个税率$7.79999999
和总计107.7999999
。我想通过做一些事情来使代码更好一点,例如从输入中删除 $,如果用户错误地输入 $,并四舍五入到最接近的分。首先,我需要了解为什么我没有得到任何输出或添加,对吧?