01-13-2010, 09:37 AM
I'm sorry, I know this thread is pretty old, but I couldn't bare seeing the problem not solved.
You have a few errors in your code, which I'll point and and try to explain the fix.
Here is what the Code should be:
First off, you should always include:
This way, it will still work if someone has ruby installed on a different directory to you.
Second;
You don't need the END statement at the bottom there, there is no BEGIN, or IF statement above, so the end if un-called for.
Third:
The way you set that up isn't very clean / clear to read. Even if you type in your name, it will say Hello, that's a nice name etc.. + the next bit.
Try doing:
So you're basically moving the top bit below your name bit. It's telling your program that if your name DOESN'T equal Ehab, then it will skip the Hello Master bit and move on to the next bit.
Fourth:
Where you have the "pass == gets.chomp" that's a simple error, you're saying if the password EQUALS what they put in.. it doesn't make any sense.
It should be:
Fifth:
The if pass and what not is all right, except for the bottom. I am new to Ruby, and I'm not sure how to use the ELSE statement yet, but where you have it there is wrong. The two bottom snippets should be:
I hope that helps you out and I explained it clearly enough. Keep it up with Ruby though!
You have a few errors in your code, which I'll point and and try to explain the fix.
Here is what the Code should be:
Code:
#! /urb/bin/env ruby
puts 'Hello World!'
puts 'Well, this is my first program in ruby :)'
puts 'So, What is your name?'
name = gets.chomp
puts 'Very Nice Name,' + name
puts 'Well, I hope you enjoyed my Program'
puts 'Goodbye! :) '
puts ' '
if name == 'Ehab'
puts 'Oh, Hello Master'
puts 'Thank you for creating me'
puts 'Work Harder learning ruby, so you can make me better'
puts ' '
puts 'If you want to enter the matrix, please type the password'
pass = gets.chomp
if pass == 'ruby'
puts 'Congratulations, You Have Cracked The Password!'
end
end
First off, you should always include:
Code:
#! /usr/bin/env ruby
Second;
Code:
puts 'Hello World!'
puts 'Well, this is my first program in ruby :)'
puts 'So, What is your name?'
name = gets.chomp
puts 'Very Nice Name,' + name
puts 'Well, I hope you enjoyed my Program'
puts 'Goodbye! :) '
puts ' '
end
Third:
Code:
if name == 'Ehab'
puts 'Oh, Hello Master'
puts 'Thank you for creating me'
puts 'Work Harder learning ruby, so you can make me better'
puts ' '
puts 'If you want to enter the matrix, please type the password'
pass == gets.chomp
Try doing:
Code:
if name == 'Ehab'
puts 'Oh, Hello Master'
puts 'Thank you for creating me'
puts 'Work Harder learning ruby, so you can make me better'
puts ' '
puts 'If you want to enter the matrix, please type the password'
pass == gets.chomp
if name != 'Ehab'
puts 'Hello World!'
puts 'Well, this is my first program in ruby :)'
puts 'So, What is your name?'
name = gets.chomp
puts 'Very Nice Name,' + name
puts 'Well, I hope you enjoyed my Program'
puts 'Goodbye! :) '
puts ' '
Fourth:
Code:
if name == 'Ehab'
puts 'Oh, Hello Master'
puts 'Thank you for creating me'
puts 'Work Harder learning ruby, so you can make me better'
puts ' '
puts 'If you want to enter the matrix, please type the password'
pass == gets.chomp
It should be:
Code:
if name == 'Ehab'
puts 'Oh, Hello Master'
puts 'Thank you for creating me'
puts 'Work Harder learning ruby, so you can make me better'
puts ' '
puts 'If you want to enter the matrix, please type the password'
pass = gets.chomp
Fifth:
Code:
if pass == 'ruby'
puts 'Congratulations, You Have Cracked The Password!'
else
end
Code:
if pass == 'ruby'
puts 'Congratulations, You Have Cracked The Password!'
end
end
I hope that helps you out and I explained it clearly enough. Keep it up with Ruby though!
At the top will be the same place you hang from.