Multiplying variables in Ruby? -
i'm trying create simple pay predictor program.
i capturing 2 variables, want multiply variables. have tried doing
pay = payrate * hourrate
but seems not work. told set pay
in definition, tried display variable still didn't work. when looked @ documentation, seems using right operator. guesses?
# simple budgeting programme puts "what budget type?\nyou can 'monthly' 'weekly' or 'fortnightly'" payperiod = gets.chomp case payperiod when "monthly" puts "you paid monthly" when "weekly" puts "you paid weekly" when "fortnightly" puts "you paid every 2 weeks." else puts "you did not input right answer." end puts "what hourly rate?\n" payrate = gets.chomp puts "how many hours have worked during pay period?\n" hourrate = gets.chomp def pay payrate * hourrate end puts "#{pay}" preventclose = gets.chomp
the def
has nil it. payrate
, hourrate
strings , *
means different thing strings. need convert them numbers first to_i
or to_f
.
payrate.to_f * hourrate.to_f
ruby variables
No comments:
Post a Comment