2015-10-19 96 views
-1

puts'請一次輸入10個數字。用戶輸入10個整數。需要對計數的整數和最大整數進行計數

VALUE_LIST = []陣列中的#stores號碼

計數= 0 uicomp = 0

而計數 UI = INT(的raw_input( '請輸入一個整數|' + STR (10-count)+'remain:'))#input countdown display if ui> uicomp; #檢查電流輸入,看它是否比前 uicomp = UI#存儲可變更大重新綁定 數+ = 1個#迭代增量 結束 結束

10.times做#can還用我在1..10做 VALUE_LIST < < gets.chomp.to_i 結束

提出「從輸入的數字最大的整數爲:#{} value_list.max」

+0

'int(raw_input'?看起來像Python? – steenslag

+0

請編輯以使標題更有意義,並刪除「Noob to Ruby」,並在正文中陳述您的問題。如果你在這裏看到其他的標題,你會發現沒有一個與你最微弱的相似。 –

回答

0

我不明白你想要什麼,但它應該解決您的問題:

puts 'Please enter 10 numbers one at a time.' 

max = 0 

1.upto(10) do |count| 
    puts "Please enter an integer number | #{10-count} remain:" #input countdown display 
    num = gets.chomp.to_i 

    if num > max #check current input to see if it's larger than the previous 
    max = num # Store variable rebind 
    end 

end 

puts "Largest integer from the numbers entered is: #{max}" 
+0

現在「count」沒有被定義(錯誤)。 – steenslag

+0

我定義了count = 0,但是當我輸入一個整數時不倒計數 – Mbxray

+0

確保count在循環之外被定義。 – Doon