From: Isaac Sanders Date: 2011-11-30T00:27:14+09:00 Subject: Re: What's wrong with this code? --20cf300e4fbfdea99c04b2e14004 Content-Type: text/plain; charset=ISO-8859-1 Why are you using so many instance variables (atvars or @vars)? If you removed the @'s it might add to the readability of your code. Also, I believe that you are calculating the time wrong, but I am not quite sure. Also, the intent and structure of your code is confusing. Try extracting some more methods. If I am not right, please let me know. On Tue, Nov 29, 2011 at 10:20 AM, Kenley T. wrote: > It's still not working. Still has the same error. Here's the new code: > puts 'Enter your goal words for today' > @goal = gets.chomp.to_i > @count = 0 > @now = Time.new > @thir = Time.new + (30 * 60) > @en_points = 0 > @ur_points = 0 > while @count != @goal > if @now == @thir > @num = 500 + rand(300) > puts "#{@num}" + ' is your enemy word count. How did you fare?' > puts 'Enter how many words you typed during the thirty miinutes' > @cur = gets.chomp.to_i > @count = @count + @cur > if @cur < @num > puts 'You lost' > @en_points = @en_points + 1 > puts 'Enemy: ' + "#{@en_points}" + ' You: ' + "#{@ur_points}" > elsif @cur == @num > puts 'A tie' > puts 'Enemy: ' + "#{@en_points}" + ' You: ' + "#{@ur_points}" > else > puts 'You won' > @ur_points = @ur_points + 1 > puts 'Enemy: ' + "#{@en_points}" + ' You: ' + "#{@ur_points}" > end > else > @now = Time.new > end > end > > if @en_points > @ur_points > puts 'You lost despite success.' > elsif @en_points == @ur_points > puts 'A tie, but you succeeded in writing a lot of words.' > else > puts 'Multiple victories!' > end > > I think you should try running it just to be safe, so the file is > attached. > Thanks! > > Attachments: > http://www.ruby-forum.com/attachment/6803/enemy.rb > > > -- > Posted via http://www.ruby-forum.com/. > > -- Sincerely, Isaac Sanders --20cf300e4fbfdea99c04b2e14004--