User Input Integers

F

flebber

using 1.9.1

I have google searched this but there seems to be a very broad array
of answers none very consistent.

Can someone put to bed the exact way to get user input with "Integers"
and specify how many decimals to output too in this case 2 decimals.

Here is a basic program(not working) to calculate netpay.

puts "How many hours did you work?"
hours = gets.chomp()._to.i
puts "What is your tax rate?"
taxrate = gets.chomp()._to.i
tax = (100 - taxrate)
netpay = ((hours * 12.00) * tax))
puts "Your netpay is, $" $netpay
 
A

Abinoam Jr.

using 1.9.1
I have google searched this but there seems to be a very broad array
of answers none very consistent.

:) :-D Sorry... but I really don't believe it!
Can someone put to bed the exact way to get user input with "Integers"
and specify how many decimals to output too in this case 2 decimals.

Yes! To do your home work? Ok :)
Here is a basic program(not working) to calculate netpay.
puts "How many hours did you work?"
hours =3D gets.chomp()._to.i
puts "What is your tax rate?"
taxrate =3D gets.chomp()._to.i
tax =3D (100 - taxrate)
netpay =3D ((hours * 12.00) * =A0tax))
puts "Your netpay is, $" $netpay

Use this code bellow solely as a guide.

puts "How many hours did you work?"
hours =3D gets.chomp().to_i
puts "What is your tax rate?"
taxrate =3D gets.chomp().to_i
tax =3D (100 - taxrate)
netpay =3D ((hours * 12.00) * tax)
printf "Your netpay is, US$ %.2f", netpay

Aside the code errors, I think your calcs are wrong.

Wouldn't it be something like...

netpay =3D ((hours * 12.00) * tax) / 100 # with this 100 dividing it.

Abinoam Jr.
 
F

flebber

:) :-D Sorry... but I really don't believe it!


Yes! To do your home work? Ok :)


Use this code bellow solely as a guide.

puts "How many hours did you work?"
hours = gets.chomp().to_i
puts "What is your tax rate?"
taxrate = gets.chomp().to_i
tax = (100 - taxrate)
netpay = ((hours * 12.00) *  tax)
printf "Your netpay is, US$ %.2f", netpay

Aside the code errors, I think your calcs are wrong.

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
:) :-D 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.

For multiple integer input

q = 1
$stdin.readline.split.each {|n| q *= n.to_i }
p q


*result number 3 is drum roll me with this thread http://www.ruby-forum.com/topic/709485

Sadly no decent Ruby Documentation comes up in the google search, even
sader this thread is already in the top 3.
 
F

flebber

:) :-D Sorry... but I really don't believe it!


Yes! To do your home work? Ok :)


Use this code bellow solely as a guide.

puts "How many hours did you work?"
hours = gets.chomp().to_i
puts "What is your tax rate?"
taxrate = gets.chomp().to_i
tax = (100 - taxrate)
netpay = ((hours * 12.00) *  tax)
printf "Your netpay is, US$ %.2f", netpay

Aside the code errors, I think your calcs are wrong.

Wouldn't it be something like...

netpay = ((hours * 12.00) *  tax) / 100 # with this 100 dividing it.

Abinoam Jr.

Oh and flattery will get you nowhere.
Yes! To do your home work? Ok :)

My oldest girl is starting school in 2011 and no my name isn't Kerney.
 
A

Abinoam Jr.

Oh and flattery will get you nowhere.

The only thing I can say now is (sincerely) "sorry"!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top