0

My code is stuck within while-loop. It keeps looping back to the Backup_power (refer to the image below). enter image description here

lowest = 38
puts 'Read Temperature:'
t = gets.chomp.to_f

if(t < lowest)
 lowest = t
end
while t<=80 || bpower=='on'
  puts 'Enter backup power (on/off):'
  bpower = gets.chomp

  if(t<50)
    puts 'Normal mode of operation'
  else
    if(t<=80 || bpower=='on')       
      puts 'On the fan'
    else
      puts'Turn off equipment'
    end
  end
  puts lowest
end
10
  • Please tell us what you're trying to do. Show us some code and explain where you are struggling. Commented Apr 9, 2020 at 7:29
  • i had inserted the picture Commented Apr 9, 2020 at 7:32
  • 1
    "Can somebodyy help me?" is not a precise enough error description for us to help you. What doesn't work? How doesn't it work? What trouble do you have with your code? Do you get an error message? What is the error message? Is the result you are getting not the result you are expecting? What result do you expect and why, what is the result you are getting and how do the two differ? Is the behavior you are observing not the desired behavior? What is the desired behavior and why, what is the observed behavior, and in what way do they differ? Commented Apr 9, 2020 at 7:36
  • i had already edit the question. Theres a link beside it for the program that i am required to do Commented Apr 9, 2020 at 7:41
  • You've posted your code. Now can you say where in the code you're getting the problem. Is there an error message? What does it say? Commented Apr 9, 2020 at 7:47

1 Answer 1

1

You are almost there!
The problem is you did not include the Read Temperature inside the loop. So how do you intend to read the new temperature?

I will give you a hint:

lowest = 38
t=0
bpower="on"

while t<=80 || bpower=='on'
  Read Temperature
Sign up to request clarification or add additional context in comments.

2 Comments

hmmmm i am should i puts:Read temperature below the while loop?
well, according to your design. Nice flowchart by the way, easy to understand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.