[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Strange Ruby Issue in SciTE - Won't Parse First Input

Michael Boutros

3/17/2007 6:44:00 PM

NOTE: I posted this in the RForum category accidentally, and it seems
very dead there so here I am.

Yeah, I know. Very bad topic title, but there is no quick way to
describe this problem in 2 words:

I am learning Ruby right now, and I am using the wonderful Learning Ruby
guide by Satish Talim. I am currently at the chapter "Random Numbers"
and I am trying to do the following:

This assignment is from Chris Pine's Book.

1. Write a Deaf Grandma program. Whatever you say to grandma
(whatever you type in), she should respond with HUH?! SPEAK UP, SONNY!,
unless you shout it (type in all capitals). If you shout, she can hear
you (or at least she thinks so) and yells back, NO, NOT SINCE 1938! To
make your program really believable, have grandma shout a different year
each time; maybe any year at random between 1930 and 1950. You can't
stop talking to grandma until you shout BYE.
2. Extend your Deaf Grandma program: What if grandma doesn't want you
to leave? When you shout BYE, she could pretend not to hear you. Change
your previous program so that you have to shout BYE three times in a
row. Make sure to test your program: if you shout BYE three times, but
not in a row, you should still be talking to grandma.

I have done all of that, but I have one problem. I am using SciTE, and
am using the F5 thing to try out my code. My one problem is that when I
run the program, the correct text comes on, but I have to press enter
twice for the while loop to start. Sounds confusing, I know, so here is
my code:

bye_response = 0
years = (1930..1950).to_a

puts "'Ey sonny! Long time no chat with your old nonna, eh? How ya
been!?"
STDOUT.flush

response = gets.chomp
while bye_response != 3
response = gets.chomp
if bye_response == 2
puts "FINE! LEAVE YOUR OLD NONNA!"
bye_response += 1
elsif response == "BYE"
puts "HUH!? WHAT WAS THAT!?"
bye_response += 1
elsif response == response.upcase
puts "NO, NOT SINCE " + years[rand(years.max - years.min)].to_s +
"!"
bye_response = 0
else
puts "HUH?! SPEAK UP, SONNY!"
bye_response = 0
end
STDOUT.flush
end

Try it out in SciTE and you'll see what I mean. If you don't have SciTE
and still want to see what I mean, I took a screenshot:
http://www.michaelboutros.com/upload.... Thanks a lot!

--
Posted via http://www.ruby-....

4 Answers

Michael Boutros

3/17/2007 6:47:00 PM

0

Sorry! I didn't post the updated code:

bye_response = 0
years = (1930..1950).to_a

puts "'Ey sonny! Long time no chat with your old nonna, eh? How ya
been!?"
STDOUT.flush

response = gets.chomp

while bye_response != 3
response = gets.chomp
if response == "BYE"
if bye_response == 2
puts "FINE! LEAVE YOUR OLD NONNA!"
else
puts "HUH!? WHAT WAS THAT!?"
end
bye_response += 1
elsif response == response.upcase
puts "NO, NOT SINCE " + years[rand(years.max - years.min)].to_s +
"!"
bye_response = 0
else
puts "HUH?! SPEAK UP, SONNY!"
bye_response = 0
end
STDOUT.flush
end


--
Posted via http://www.ruby-....

David Kastrup

3/17/2007 6:53:00 PM

0

Michael Boutros <me@michaelboutros.com> writes:

> I have done all of that, but I have one problem. I am using SciTE, and
> am using the F5 thing to try out my code. My one problem is that when I
> run the program, the correct text comes on, but I have to press enter
> twice for the while loop to start.

No, you have to press enter once for the while loop to start, and
another time _in_ the while loop:

> bye_response = 0
> years = (1930..1950).to_a
>
> puts "'Ey sonny! Long time no chat with your old nonna, eh? How ya
> been!?"
> STDOUT.flush
>
> response = gets.chomp

Here you have demanded the first enter.

> while bye_response != 3
> response = gets.chomp

And here you have demanded the second one, before even doing anything
with the previous response.

I suggest that you remove the first of those lines asking for input:
it does not actually get used anywhere.

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum

Michael Boutros

3/17/2007 7:01:00 PM

0

David Kastrup wrote:
> I suggest that you remove the first of those lines asking for input:
> it does not actually get used anywhere.

Ah, that makes sense. Thanks a lot for your help David :)

--
Posted via http://www.ruby-....

GLOBALIST

5/25/2013 10:15:00 PM

0

On Saturday, May 25, 2013 5:05:45 PM UTC-5, Gary wrote:
> On Sat, 25 May 2013 09:39:13 -0700, Islander <nospam@priracy.net>
>
> wrote:
>
>
>
> >On 5/25/2013 6:01 AM, Gary wrote:
>
> >> I figure I'm a typical retiree. And to be perfectly honest -- I
>
> >> don't give a damn about what gays do. Nor about what blacks do.
>
> >> Nor about what "undocumented" workers do.
>
> >>
>
> >> There was a time I was interested in such activities. But I am now
>
> >> on Social Security and Medicare. Of all political issues -- those
>
> >> are the two I'm most personally concerned with.
>
> >>
>
> >> So what ? IMO, the dumbest voters in America are the 18-35
>
> >> group. They are very gullible and form most of their opinions from
>
> >> the TV programs they watch. The good thing is .... they don't vote
>
> >> all that much.
>
> >>
>
> >> If we keep this gay marriage issue in the public very long -- these
>
> >> voters will be activated by the TV hosts (all liberal and all for
>
> >> gays) to get out and vote -- for gay marriage. Now here is our
>
> >> problem. While they are out supporting gays -- they will also vote
>
> >> against the issues that mean most to us retirees. Idiots do that.
>
> >>
>
> >> Their battle cry will be:
>
> >>
>
> >> "Social Security is robbing us to pay old folks" !!
>
> >>
>
> >
>
> >I've got news for you Gary. You are not typical.
>
>
>
> I may be noisier than most, but I think I'm pretty typical. Some
>
> people sometimes get the erroneous impression I hate certain minority
>
> groups, just because I criticize their effect on our culture. Such
>
> is not the case.

We all know from the civil rights days of Martin Luther King etc. that all
the laws on the books can not force 'anyone' to like or respect
other folks. You still tread lightly, from the other side, realizing
your legal rights might be on paper, but they do not change
peoples hearts/minds