Vincent Gabriel Franco
2/7/2007 5:07:00 AM
Thank you Jason,
That process had skipped my mind for some reason I thought just
setting the variable to true would kill the loop.
this is my revised code.
My first program without just typing out an example from a book
here we go.
any suggestions on how to clean it up would be great.
----------------------------------------------------------------------
first_number = []
second_number = []
answer = []
quit = false
def check_if_blank input
if(input == '')
return true
else
return false
end
end
while (quit == false)
if(quit == false)
puts 'Enter a number'
first = gets.chomp
first_test = check_if_blank first
if(first_test == false)
first_number.push first.to_i
else
quit = true
end
end
if(first_test == false)
puts '...good.'
puts 'Now enter a number to multiply to the first number'
second = gets.chomp
second_test = check_if_blank second
if(second_test == false)
second_number.push second.to_i
answer.push first_number[(first_number.length) -1] *
second_number[(second_number.length) -1]
puts first_number[(first_number.length) -1].to_s + ' * '
+ second_number[(second_number.length) -1].to_s + ' = ' +
answer[(answer.length) -1].to_s
else
quit = true
end
end
if(second_number.length == 5)
quit = true
end
end
if(second_test == false)
finished = false
amount_of_answers = 0
puts
puts 'okay now we are going to look at all the questions your asked
and their respective answers'
while(finished != true)
if(amount_of_answers == first_number.length)
finished = true
else
puts first_number[amount_of_answers].to_s + ' * ' +
second_number[amount_of_answers].to_s + ' = ' +
answer[amount_of_answers].to_s
amount_of_answers += 1
end
end
end
-------------------------------------------------------------------