Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 wtd, ruby questions
Index -> Programming, Ruby -> Ruby Help
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Mon Nov 08, 2004 7:12 pm   Post subject: (No subject)

Is it really "greet.rb", or did it get saved as "greet.rb.txt"?
Sponsor
Sponsor
Sponsor
sponsor
dsantamassino




PostPosted: Mon Nov 08, 2004 7:43 pm   Post subject: (No subject)

wtd wrote:
Is it really "greet.rb", or did it get saved as "greet.rb.txt"?


No i just looked. Its really on my root C: and its named greet.rb

so i tried greet.rb and ruby greet.rb both in the command and still nothing. Its doesnt recognize for some reason
wtd




PostPosted: Mon Nov 08, 2004 8:28 pm   Post subject: (No subject)

Ok... not gonna give up on this.

Try "type greet.rb" at the command-line. The Windows command prompt, not the IRB prompt.
dsantamassino




PostPosted: Mon Nov 08, 2004 8:32 pm   Post subject: (No subject)

wtd wrote:
Ok... not gonna give up on this.

Try "type greet.rb" at the command-line. The Windows command prompt, not the IRB prompt.


I tried at the C: command line both as followed and nothing

type greet.rb
"type greet.rb"

exactly both ways with quotes and without.....
wtd




PostPosted: Mon Nov 08, 2004 8:46 pm   Post subject: (No subject)

Ok, let's try a different approach... instead of using Notepad or Textpad... for now we'll just used the built-in edit program.

At the command-line, enter:

code:
C:\> edit greet.rb


You'll see a blue editor screen. Here you can type in the program again, unless it's already there. Wink

code:
puts "Your name is?"
name = gets
puts "Hello, " + name + "!"


You can use Alt-F-S to save, and Alt-F-X to exit.

Then to run it:

code:
C:\> ruby greet.rb
dsantamassino




PostPosted: Mon Nov 08, 2004 9:34 pm   Post subject: (No subject)

ok.. here is a different error message down below..

greet.rb:3: syntax error
puts "Hello, " + Derek "!"
wtd




PostPosted: Mon Nov 08, 2004 9:43 pm   Post subject: (No subject)

dsantamassino wrote:
ok.. here is a different error message down below..

greet.rb:3: syntax error
puts "Hello, " + Derek "!"


Cool.

You're missing a + between Derek and "!".

The name of the variable should also be "name". Smile
dsantamassino




PostPosted: Mon Nov 08, 2004 9:48 pm   Post subject: (No subject)

wtd wrote:
dsantamassino wrote:
ok.. here is a different error message down below..

greet.rb:3: syntax error
puts "Hello, " + Derek "!"


Cool.

You're missing a + between Derek and "!".

The name of the variable should also be "name". Smile


Cool it worked.
Derek?
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Mon Nov 08, 2004 10:41 pm   Post subject: (No subject)

Spiffy.

Now, do you understand why the program went something like:

code:
C:\> ruby greet.rb
And your name is?
Derek
Hello, Derek
!

C:\>


When it should have looked like:

code:
C:\> ruby greet.rb
And your name is?
Derek
Hello, Derek!

C:\>
dsantamassino




PostPosted: Mon Nov 08, 2004 10:44 pm   Post subject: (No subject)

wtd wrote:
Spiffy.

Now, do you understand why the program went something like:

code:
C:\> ruby greet.rb
And your name is?
Derek
Hello, Derek
!

C:\>


When it should have looked like:

code:
C:\> ruby greet.rb
And your name is?
Derek
Hello, Derek!

C:\>


No i dont know. May u explain it to me??
wtd




PostPosted: Mon Nov 08, 2004 10:48 pm   Post subject: (No subject)

Sure.

When you call "gets" to get input from the user, you get all of their input, including the return key.

Then, then you use "puts" to output, you get that return again.

The key is to use another method named "chomp" to remove the return from the end of that string.

code:
puts "And your name is?"
name = gets.chomp
puts "Hello, " + name + "!"
dsantamassino




PostPosted: Mon Nov 08, 2004 10:50 pm   Post subject: (No subject)

wtd wrote:
Sure.

When you call "gets" to get input from the user, you get all of their input, including the return key.

Then, then you use "puts" to output, you get that return again.

The key is to use another method named "chomp" to remove the return from the end of that string.

code:
puts "And your name is?"
name = gets.chomp
puts "Hello, " + name + "!"


Oh ok i think i got it
wtd




PostPosted: Mon Nov 08, 2004 11:09 pm   Post subject: (No subject)

An exercise, shamelessly stolen from Chris Pine:

Write a program which asks for a person's first name, then middle, then last. Finally, it should greet the person using their full name.
dsantamassino




PostPosted: Tue Nov 09, 2004 5:48 pm   Post subject: (No subject)

I tired to do it but its pointed an upward error to the middle name
wtd




PostPosted: Tue Nov 09, 2004 6:20 pm   Post subject: (No subject)

Post the code you write. Please surround it with code tags, like so:

code:
[code]This is formatted as code.[/code]
Display posts from previous:   
   Index -> Programming, Ruby -> Ruby Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 7 of 9  [ 129 Posts ]
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
Jump to:   


Style:  
Search: