def guessing_game():Unit = {
println("Welcome to the guessing game!!")
val guess_count:Int = 0
val answer = Random.nextInt(50)
var guess_num = scala.io.StdIn.readLine("Input your guess number > ").toInt
while(guess_num != answer || guess_count < 5){
====> guess_count += 1 // <==============================
var situation = if(guess_num > answer){"Your guess is higher!"}else{"Your guess is lower!"}
println(situation)
guess_num = scala.io.StdIn.readLine("Input your guess number > ").toInt
}
if(guess_num == answer){
println("Congratulation....You win!!")
}else{
println("You hav run out of guess!")
}
それは言う: エラー:(16、25)値+ =レシーバが割り当て可能でないため、割り当てに変換しないのInt 式のメンバーではありません。 guess_count.toInt + = 1なぜ私はscalaでインクリメントできませんか?
ありがとうございます! 作品 –