Skip to content

Instantly share code, notes, and snippets.

@Code-Hex
Created August 18, 2014 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Code-Hex/c8156f10439aa39b1261 to your computer and use it in GitHub Desktop.
Save Code-Hex/c8156f10439aa39b1261 to your computer and use it in GitHub Desktop.
rubyの練習。その2
#! /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}個の果物がはいったよ"
@Code-Hex
Copy link
Author

STDINを使って
if文とcase文、while文をやったよ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment