Salve a tutti.
Mi chiamo Angelo e da qualche mese so imparando ad
usare Ruby su un tutorial.
Ultimamente non riesco a risolvere un
esercizio e così mi rivolgo a questa Comunità .
Il programma in
questione è il seguente:
# encoding: utf-8
comando = ' '
if
(comando.capitalize != 'Stop')
while (comando.capitalize != 'Stop')
comando = gets.chomp
puts 'Il gallo è morto'
puts 'Il gallo è
morto'
puts 'E più non canterà coccodì e coccodà '
puts 'E più non
canterà coccodì e coccodà '
puts 'Uè!'
puts ' '
end
if
(comando.capitalize == 'Stop')
puts ' '
puts 'OK la smetto :-)'
end
end
pausa = gets
Il risultato è che finché non digito 'stop'
il programma mi restituisce la canzoncina ad ogni invio.
Ma quando
digito 'stop' il programma mi restituisce:
Il gallo è morto
Il gallo
è morto
E più non canterà coccodì e coccodÃ
E più non canterÃ
coccodì e coccodÃ
'Uè!
OK la smetto
Io invece vorrei che
digitando il comando 'stop' il programma mi restituisca solo:
OK la
smetto
Qualcuno mi può dire la soluzione di questo problema?
Grazie a tutti.
Angelo
Hello everyone.
My name is Angelo and for
some months I have been learning how to use Ruby on a tutorial.
Lately
I have not been able to solve an exercise and so I turn to this
community.
The program in question is as follows:
# encoding: utf-8
command = ''
if (command.capitalize! = 'Stop')
while
(command.capitalize! = 'Stop')
command = gets.chomp
puts 'The
rooster is dead'
puts 'The rooster is dead'
puts 'And the more he
will not sing cuddly and cuddly'
puts 'And no more will he sing huff
and huff'
puts 'Hey!'
puts ''
end
if (command.capitalize ==
'Stop')
puts ''
puts 'OK I'll stop :-)'
end
end
pause = gets
The result is that until I type 'stop', the program returns the song
to me at each sending.
But when I type 'stop' the program gives me:
The rooster died
The rooster died
And no longer will he sing
cuddly and cuddly
And no longer will he sing cuddly and cuddly
'Uè!
Ok I'll stop
On the other hand, I would like the program to
return me only by typing the 'stop' command:
Ok I'll stop
Can
anyone tell me the solution of this problem?
Thank you all.
Angelo
···
--
_ANGELO BALDELLI _
Con Tiscali Mobile Smart 70 hai 70 GB in 4G, minuti illimitati e 100 SMS a soli 7,99⬠al mese Offerte Telefonia mobile voce e Internet - Tiscali Casa