Hi there
I am a C++ person but trying to help a friend using Ruby.
He is supposed to ask for user input by using an index number to change
the letter of a word given, like say “dog”. So the user it asked to
enter the index number, lets say 0 is entered by the user, and he then
asks the user to put a new letter in (letter is a variable), then he
wants to change the index of 0 which is the “D” to a “C” (where c was
put in by the user).
Can anyone help with this? How to do it please?
Cheryl
Cheryl Cepak wrote:
Hi there
I am a C++ person but trying to help a friend using Ruby.
He is supposed to ask for user input by using an index number to change
the letter of a word given, like say “dog”. So the user it asked to
enter the index number, lets say 0 is entered by the user, and he then
asks the user to put a new letter in (letter is a variable), then he
wants to change the index of 0 which is the “D” to a “C” (where c was
put in by the user).
Can anyone help with this? How to do it please?
Cheryl
Here is what he has so far:
student_name = ‘John Wallace’
puts student_name + “'s WordWarp Game!”
require ‘zlib’
dictionary = Zlib::GzipReader.open(‘words3-8.gz’).read().split()
current_word = ‘dog’
target_word = ‘cat’
puts
puts current_word.to_s + ’ => ’ + target_word.to_s
puts ‘What is the index of the letter you wish to change?’
index = gets
puts ‘What letter do you wish to insert?’
letter = gets
temp_word = current_word.clone()
puts temp_word
On Tue 2.Dec’08 at 13:24:28 +0900, Cheryl Cepak wrote:
I am a C++ person but trying to help a friend using Ruby.
He is supposed to ask for user input by using an index number to change
the letter of a word given, like say “dog”. So the user it asked to
enter the index number, lets say 0 is entered by the user, and he then
asks the user to put a new letter in (letter is a variable), then he
wants to change the index of 0 which is the “D” to a “C” (where c was
put in by the user).
my_str = “Dog”
p “Before: #{my_str}”
puts “Index?” ; i = Integer(gets)
puts “letter?”; c = gets.chomp
my_str[i] = c
puts “After: #{my_str}”
-drd