Skip to content

Instantly share code, notes, and snippets.

@ecmelkytz
Created March 29, 2013 16:10
Show Gist options
  • Save ecmelkytz/5271800 to your computer and use it in GitHub Desktop.
Save ecmelkytz/5271800 to your computer and use it in GitHub Desktop.
#!usr/bin/ruby
#encoding: utf-8
#Bilgisayarin urettigi sayiyi tahmin etme oyunu
puts "Tahmin icin 0-100 arasi bir sayi giriniz."
puts "Cikmak icin q ya basin"
tahmin_sayisi = 1
s = Random.new
sayi = s.rand(0..100)
while 1
puts "Bir sayi giriniz:"
tahmin=gets
if tahmin.to_i == sayi
puts "Tebrikler #{tahmin_sayisi} kerede sayiyi buldunuz."
break
elsif tahmin.to_i > sayi
puts "Buyuk bir tahmin oldu.Biraz asagiya in"
tahmin_sayisi += 1
elsif tahmin.to_i < sayi
puts "Kucuk bir tahmin oldu.Biraz yukariya cik"
tahmin_sayisi += 1
elsif tahmin == "q"
break
elsif 0 >= tahmin || 100 <= tahmin
puts "Girilen sayi 0-100 arasi degil.Tekrar deneyiniz"
tahmin_sayisi += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment