Yes! To do your home work? Ok
Use this code bellow solely as a guide.
Wouldn’t it be something like…
netpay = ((hours * 12.00) * tax) / 100 # with this 100 dividing it.
Abinoam Jr.
The Top 3 results from google for Ruby user input integers
I have google searched this but there seems to be a very broad array
of answers none very consistent.
Sorry… but I really don’t believe it!
*top result stackoverflow
Answer
s = []
for i in 1…3
puts “What is point " + i.to_s + " ?” # asks for input
s.push gets.split(" ").map {|x| x.to_i }
end
if s[1][0] - s[0][0] == 0 # notice the ‘==’.
puts ‘It worked!’
end
*In second place well sadly the result was stackoverflow again.
I have a problem getting user input with gets method.
The following is a very simple code snippet for me to try this method:
print "What’s your name? "
my_name = gets
puts "Nice to meet you " + my_name + “!”
When I try to run the code, this is the error that i get:
What’s your name? TypeError: can’t convert nil into String
How do i fix it? By the way, I am using Ruby 2.0. I have tried on my PC
as well as on my android phone with Ruboto, still the error message. All
the books I have been reading, they have been using exactly this format:
my_name = gets
What’s your name? TypeError: can’t convert nil into String
How are you executing this? Because here works fine:
┌─[atma@air] - [~] - [Δευ Μαρ 17, 01:22]
└─[$] <> cat test.rb
print "What’s your name? "
my_name = gets
puts "Nice to meet you " + my_name + “!”
┌─[atma@air] - [~] - [Δευ Μαρ 17, 01:22]
└─[$] <> ruby test.rb
What’s your name? Nick
Nice to meet you Nick
!
┌─[atma@air] - [~] - [Δευ Μαρ 17, 01:22]
└─[$] <> ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.0.0]
┌─[atma@air] - [~] - [Δευ Μαρ 17, 01:22]
└─[$] <>
How do i fix it? By the way, I am using Ruby 2.0. I have tried on my PC
as well as on my android phone with Ruboto, still the error message. All
the books I have been reading, they have been using exactly this format:
my_name = gets