title: Kotlin: I am unable to hold previous value of a function when calling it multiple times
body: <p>I need to show different seat arrangement till the user is making choices and register it's previous choices as well in the displayed seat arrangement.
  My code is:</p>
  <pre><code>package cinema
  
  fun main() {
      println(&quot;Enter the number of rows:&quot;)
     val row = readLine()!!.toInt()
     
     println(&quot;Enter the number of seats in each row&quot;)
     val seats = readLine()!!.toInt()
     var price = 0
     
     
     val totalSeats = row*seats
     var rowNumberUpdate = 0
     var seatNumberUpdate = 0
     var a = true
     
      fun seatDisplay(){
             var newSeatCount = 1
             println(&quot;Cinema: &quot;)
                  print(&quot; &quot;)
          
                  while(newSeatCount &lt;=seats){
              
                      print(&quot; $newSeatCount&quot;)
                      newSeatCount += 1
                  }
          
                  print(&quot;\n&quot;)
                  for(i in 1..row){
          
                      print(i)
          
                      for(j in 1..seats){
                          if(i == rowNumberUpdate &amp;&amp; j==seatNumberUpdate) print(&quot; B&quot;) else print(&quot; S&quot;) 
             
             
                      }
                      println()
                  }
         }
     
      fun priceDisplay(){
             println(&quot;Enter a row number: &quot;)
                   val rowNumber = readln().toInt()
                   rowNumberUpdate = rowNumber
                   println(&quot;Enter a seat number in that row: &quot;)
                   val seatNumber = readln().toInt()
                   seatNumberUpdate = seatNumber
     
                   if(totalSeats&lt;=60){
                       price = 10
                   } else {
                         if(row%2==0){
                             if(rowNumber&lt;=row/2) price = 10 else price = 8
                          } else {
                                if(rowNumber&lt;=row/2) price = 10 else price = 8
                            }
                      }
                  println(&quot;Ticket price: $$price&quot;)
         }
         
         
     
         
     
     
     while(a){
         println(&quot;1. Show the seats&quot;)
         println(&quot;2. Buy a ticket&quot;)
         println(&quot;0. Exit&quot;)
         val optionsInput = readln().toInt()
         
         when(optionsInput){
              1 -&gt; seatDisplay()
     
              2 -&gt; priceDisplay()
     
              0 -&gt; a = false
  
         }
     }
         
  }
  </code></pre>
  <p>Problem with this code is, everytime user is making choice it is showing the seat arrangement as per the latest choice. It doesn't hold the value of previous choices.</p>
  <p>You can see this in output attached as an <a href="https://i.stack.imgur.com/EjPQh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EjPQh.png" alt="enter image description here" /></a>image. Please zoom the image for clear visibility.</p>
  <p>Hoping to get some help from the community.</p>