She's studying Ruby's language. Can I ask you a quick question about I/O?

Asked 2 years ago, Updated 2 years ago, 28 views

print("Enter purchase value:")
purchase=gets.chomp()

print ("Enter Sales Value:")
sell=gets.chomp()

puts(sell-purchase)

That's the code When I said 400 and 500, The result I want is 900 It's 400500 I think it's because the input is processed as a string What should I do to see the output value of 900?

ruby

2022-09-22 20:57

1 Answers

print("Enter purchase value:")
purchase=gets.chomp().to_i

print ("Enter Sales Value:")
sell=gets.chomp().to_i

puts(sell-purchase)

You can do it.


2022-09-22 20:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.