J
Jet Koten
Hi,
I'm completely new to programming and am learning using Ruby.
I'm trying to get this program working using only these basic commands
that are in my program:
puts 'Say something to the virtual hard-of-hearing Grandpa:'
while true
said=gets.chomp
year = (1930+rand(51))
counter=0
if said=='GOODBYE'
counter+=1
if counter==3
break
end
end
elsif said !=said.upcase
puts 'HUH?! SAY IT LOUDER!'
counter-=1
end
else
puts 'NO, NOT SINCE '+year.to_s+'!'
counter-=1
end
end
So basically it's supposed to be that it'll just loop forever unless you
say GOODBYE three times in a row... and not just three times with
something else in between.
Otherwise if you say anything lowcase it'll say HUH?! [...] and if you
say anything upcase it should say NOT SINCE and a random number between
1930 and 1950. I had all the basic functionality working like this:
puts 'Say something to the virtual hard-of-hearing Grandpa:'
while true
said=gets.chomp
year = (1930+rand(21))
if said !=said.upcase
puts 'HUH?! SAY IT LOUDER!'
else puts 'NO, NOT SINCE '+year.to_s+'!'
end
end
I'm really stuck about getting 'him' to break after the 3 GOODBYEs in a
row, I've written the code the best I can and now all I get are various
combinations of kEND, $end and kELSE. I'm guessing it's some kind of
scope issue but I don't know enough to know what I don't know... you
know?
Can anyone see what will get 'him' working using just the same basic
commands that are in this program already?
Thanks in advance.
I'm completely new to programming and am learning using Ruby.
I'm trying to get this program working using only these basic commands
that are in my program:
puts 'Say something to the virtual hard-of-hearing Grandpa:'
while true
said=gets.chomp
year = (1930+rand(51))
counter=0
if said=='GOODBYE'
counter+=1
if counter==3
break
end
end
elsif said !=said.upcase
puts 'HUH?! SAY IT LOUDER!'
counter-=1
end
else
puts 'NO, NOT SINCE '+year.to_s+'!'
counter-=1
end
end
So basically it's supposed to be that it'll just loop forever unless you
say GOODBYE three times in a row... and not just three times with
something else in between.
Otherwise if you say anything lowcase it'll say HUH?! [...] and if you
say anything upcase it should say NOT SINCE and a random number between
1930 and 1950. I had all the basic functionality working like this:
puts 'Say something to the virtual hard-of-hearing Grandpa:'
while true
said=gets.chomp
year = (1930+rand(21))
if said !=said.upcase
puts 'HUH?! SAY IT LOUDER!'
else puts 'NO, NOT SINCE '+year.to_s+'!'
end
end
I'm really stuck about getting 'him' to break after the 3 GOODBYEs in a
row, I've written the code the best I can and now all I get are various
combinations of kEND, $end and kELSE. I'm guessing it's some kind of
scope issue but I don't know enough to know what I don't know... you
know?
Can anyone see what will get 'him' working using just the same basic
commands that are in this program already?
Thanks in advance.