I’m trying to make this program in Ruby where the “radar’ program will measure t
ID: 3922947 • Letter: I
Question
I’m trying to make this program in Ruby where the “radar’ program will measure the speed a car is going based on two measures of distance away from the camera (input by the user)
The output should look something like this, depending on the two distances entered:
Here's the code I currently have, but erroring out:
puts 'Enter the distance for the first reading:'
reading1=gets
puts 'Enter the distance for the second reading:'
reading2=gets.to_i
puts ""
speed=((reading1-reading2)*60*60)/5280
Print 'Your speed is: '
puts speed
Explanation / Answer
# ruby code
puts 'Enter the distance for the first reading: '
reading1 = gets.to_i
puts 'Enter the distance for the second reading: '
reading2 = gets.to_i
puts ""
speed = ((reading1-reading2)*60*60)/5280
print 'Your speed is: '
puts speed.ceil
=begin
output:
Enter the distance for the first reading:
100
Enter the distance for the second reading:
15
Your speed is: 57
=end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.