Created
August 18, 2014 05:39
-
-
Save Code-Hex/c8156f10439aa39b1261 to your computer and use it in GitHub Desktop.
rubyの練習。その2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
basket = 0 | |
while 1 | |
print "果物の入力\n" | |
fruit = STDIN.gets | |
result = fruit.gsub /\n/,"" | |
# p result #改行が含まれてるか確認ができる | |
if result == "apple" || result == "melon" || result == "banana" || result == "orange" || result == "apple of gold" || result == "break" | |
case result | |
when "apple" then | |
basket += 1 | |
when "melon" then | |
basket += 2 | |
when "banana" then #then は省略可能 | |
basket += 3 | |
when "orange" | |
basket += 4 | |
when "apple of gold" | |
basket *= 10 | |
print "Big bonus!!" | |
when "break" | |
break | |
end | |
elsif result == "money" | |
basket += 100 | |
print "いいね〜\n" | |
else | |
print "それってくだもの?\n" | |
end | |
end | |
print "かごに#{basket}個の果物がはいったよ" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
STDINを使って
if文とcase文、while文をやったよ