2017-07-25 39 views
0

我想使這個簡單的程序,通過選擇單位返回重量數量。當我運行該程序就沒有問題運行,並詢問這兩個問題在if但不會返回value不能輸出結果後如果

這裏是我的代碼:

puts "What is your starting weight and ratio unit? 
1:kg.m/h 
2:gm.m/s 
3:mm.m/s" 

inputing_unit = gets.chomp 

puts "What is your ending weight and ratio unit? 
1:kg.m/h 
2:gm.m/s 
3:mm.m/s" 

ending_unit = gets.chomp 

if inputing_unit == 1 and ending_unit == 1 then 
    puts "What is your weight?" 
    input_weight = gets.chomp.to_i 
    puts "What is your ratio?" 
    input_ratio = gets.chomp.to_i 
    puts "Your moving value is #{input weight * input_ratio}" 
end 
+0

郵編,而不是圖像的代碼 –

+0

顯示顯示您的代碼... –

+1

我是新來的網站抱歉的延誤。 –

回答

1

,我可以從截圖中看到開始關於pre-last line的描述在你的puts語句的哪裏有一個錯字#{input weight * input_ratio}。您應該將...#{input weight...更改爲...#{input_weight...(帶短劃線)。

+0

它只是要求提出前兩個問題。 –

+3

我相信你會錯過轉換爲整型的類型。你的if語句應該像這樣開始'if inputing_unit.to_i == 1 and ending_unit.to_i == 1 then' –

+0

它的工作,謝謝你:D –