|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Hello, Newb Help please :)
basically i started programming yesterday..
and i have a quick question for anyone willing to help me out with what is probably a really newb poroblem. okay, here it is, loops... puts 'Hello Sonny Boy.' greeting = gets.chomp while greeting != greeting.upcase puts 'HUH?! SPEAK UP, SONNY.' greeting = gets.chomp end puts 'NO, NOT SINCE 1950!' puts 'Anything else you would like to say to me?' response = gets.chomp while response != response.upcase puts 'HUH?! SPEAK UP, SONNY!' response = gets.chomp end So is there a way i can add those loops together? man this is confusing... another thing im stuck on is I want my grandma in the program to not let me stop talking to her until i say bye in upcase letters, as you can see in this line (while response != response.upcase) but i tried adding the string 'bye' to that after the (!=), but i couldnt figure out which way would let me run the program. is there a way to do that so i cant stop talking to her until i type bye in upcase letters? thanks for reading about my brain stumps. Basically what im trying to do is: write a deaf grandma program. Whatever i say to grandma (whatever i type in), she should respond with: HUH?! SPEAK UP, SONNY! unless i shout it, (type in all capitals). If i shout, she can hear me and yells back: NO, NOT SINCE 1938. (see i have this part done, but. I want to not be able to stop talking to her until i shout bye (type bye in upcase letters). Thanks for your help. |
|
#2
|
||||
|
||||
|
I don't consider this any simpler, though it's most definitely shorter:
Code:
until (line = gets.chomp) == "BYE" puts (line == line.upcase ? "NO, NOT SINCE 1983!" : "HUH?! SPEAK UP, SONNY!") end puts "SO LONG CHESTER! DON'T FORGET YOUR LEMONADE!" I'll do my best to explain what's going on in those four lines of ruby.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Hello, Newb Help please :) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|