So I have to create a ruby file for class that asks the individual to
enter two numbers, which are then put into equations to provide the
addition, subtraction, multiplication, and division. The trouble I am
having is when the individual is asked to enter their number they are
supposed to be unable to enter 0 as a number and if they do it is
supposed to loop them back to the original question. I can not figure
out how to do this correctly. Below is my file, so if anyone can show
and inform me how this is done I would GREATLY appreciate it.
class NumberCruncher
class Screen
def cls
puts ("\n" * 25)
end
end
Console_Screen = Screen.new
Console_Screen.cls
puts "Please enter a number now. (Press Enter)"
number1 = STDIN.gets
number1.chomp!
puts “Please enter a new number now. (Press Enter)”
number2 = STDIN.gets
number2.chomp!
Console_Screen.cls
print “Added first and second number.\n” , (number1.to_i +
number2.to_i)
pause = STDIN.gets
Console_Screen.cls
print “Subtracted second from first number.\n” , (number1.to_i -
number2.to_i)
pause = STDIN.gets
Console_Screen.cls
print “Multiplied first and second number.\n” , (number1.to_i *
number2.to_i)
pause = STDIN.gets
Console_Screen.cls
print “Divided first by second number.\n” , (number1.to_i /
number2.to_i)
pause = STDIN.gets
Console_Screen.cls
puts “You’re finished!”
end