2014-02-10 75 views
-3

即時通訊我試圖讓我的代碼循環(即時通訊非常新的紅寶石) 我想讓程序循環時,它不。 我被告知,我的代碼是非常錯誤的,但無論如何,我可以讓它循環呢?如何讓我的代碼循環?

class Screen 
    def clear 
    end 

    def pause 
    STDIN.gets 
    end 
end 

class Lottery 

    attr_accessor :greeting, :register, :morereg, :goodbye, :lotterynumbers, :randomtwenty 

    def initialize 
    end 

    def say_greeting 
    greeting = "\n\n\n\t\t ***Welcome to elGordo lottery!***\n\n" + 
    "\t\t  Press Enter to continue.\n\n\n" 
    print greeting 
    end 

    def say_register 
    register = "Type in the lotterynumber you want to register and then press Enter.\n\n" 
    print register #nedenunder [@counter] 
    Lotterynumbers1 << gets.chomp.to_i 
    end 

    def say_morereg 
    morereg = "would you like to type in another lottery number? (y/n)\n" 
    print morereg 
    gets.chomp! 
    if gets.chomp! == "y" then 
     say_register 
    else 
     puts "\nThank you for the register.\n\n" 
    end 
    end 

    # def say_randomtwenty 
    # Lotterynumbers1 << << 20.times.map { rand(00000..99999).to_i } 
    # end 

    def say_goodbye 
    goodbye = "\nThank you for the register.\n\n" 
    print goodbye 
    end 
end 

#main Script Logic 

Lotterynumbers1 = [] 

Console_Screen = Screen.new 
Hej = Lottery.new #starter nyt Lotteri object 

Hej.say_greeting 
Console_Screen.pause 

Hej.say_register 
Hej.say_morereg 
puts Lotterynumbers1 

回答

0

你得到了與條件語句和循環的思想困惑,如果用戶繼續說:是(Y),那麼這將是一種循環的代碼(執行相同的操作很多次)。

但它不是

+0

是的,我做到了,抱歉「壞」後:)這裏還是新的,新的紅寶石。 – user3143672