increment - Why I can't increament in scala? -


  def guessing_game():unit = {     println("welcome guessing game!!")      val guess_count:int = 0     val answer = random.nextint(50)     var guess_num = scala.io.stdin.readline("input guess number > ").toint      while(guess_num != answer || guess_count < 5){   ====> guess_count += 1    //  <==============================        var situation = if(guess_num > answer){"your guess higher!"}else{"your guess lower!"}       println(situation)       guess_num = scala.io.stdin.readline("input guess number > ").toint     }     if(guess_num == answer){       println("congratulation....you win!!")     }else{       println("you hav run out of guess!")     } 

it says: error:(16, 25) value += not member of int expression not convert assignment because receiver not assignable. guess_count.toint += 1

guess_count immutable, (val), cannot change it. use var if need change variable.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -