2 Replies - 1063 Views - Last Post: 14 November 2011 - 12:29 PM Rate Topic: -----

#1 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Why do my program terminate?

Posted 14 November 2011 - 10:49 AM

I have following code:
Person class:
#!/usr/bin/env ruby

puts "Following commands: add student (addStud)"
_CMD = gets
if(_CMD == "addStud")
  puts "Create student"
end


But it terminates when it hits the if statment, no error mistakes
Is This A Good Question/Topic? 0
  • +

Replies To: Why do my program terminate?

#2 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 915
  • View blog
  • Posts: 3,195
  • Joined: 12-May 09

Re: Why do my program terminate?

Posted 14 November 2011 - 10:51 AM

use gets.chomp


The input also contains a newline, so it's not equal. Also, to debug things like these, you could have added an else statement with a print to show that the condition is evaluating to false.

This post has been edited by xclite: 14 November 2011 - 10:52 AM

Was This Post Helpful? 3
  • +
  • -

#3 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: Why do my program terminate?

Posted 14 November 2011 - 12:29 PM

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1