Having problem with a basic guess the number script

using UnityEngine;
using System.Collections;

public class NumberWizard : MonoBehaviour {

int max;
int min;
int guess;

// Use this for initialization
void Start () {
	
	StartGame ();
}

void StartGame () {

	max = 1000;
	min = 1;
	guess = 500;

	
	
	print ("===========================================");
	print ("Welcome to Number Wizard");
	print ("Pick a Number in your head But don't tell me!");
	
	print ("The highest number you can pick is " + max);
	print ("The lowest number you can pick is " + min);
	
	print ("Is the number higher or lower then " + guess);
	print ("UP = higher, DOWN = lower, return = equal");
	
	max = max + 1;
	
	
	
}



// Update is called once per frame
void Update () {

	if (Input.GetKeyDown(KeyCode.UpArrow)) 
	
	{
		
		min = guess;
		NextGuess ();
		
		
		
	} 
	
	else if (Input.GetKeyDown(KeyCode.DownArrow)) 
		
	{
					
		max = guess;
		NextGuess ();
		
		
	} 
	
	else if (Input.GetKeyDown(KeyCode.Return)) 
		
	{
		print ("I won!");
		StartGame ();
	}

}

void NextGuess () {
	
	guess = (max + min) / 2;
	print ("Higher or lower than " + guess);
	print ("UP = higher, DOWN = lower, return = equal");
	
	
}

}

Above is the code … What i really wanted to do is for it to guess the number … but as soon as i start pressing up or down arrow like 6 - 7 times , the guess gets stuck in a single number as indicated by the image and result in console below … dont understand this behavior at the moment … Can u plz help me out in this regard … Thanks

[38930-screen+shot+2015-01-16+at+9.38.18+pm.png|38930]

I’m not sure I understand your issue because it seems to be correctly doing what you want… It is stuck on 15 in this case because you had max at 16 and min at 14 so your next guess would have put it at 15 min max 16… so the middle would be 15.5 but since you are using an int it is truncated. Tracing your logic from the output it seems to be the following:

since you’re at 125, you clearly hit DOWN for lower at first… so it went to 1 - 500 so picked 250… so hit DOWN again and it went to 1 - 250 so picked 125. hit DOWN again so 1 - 125 so picked 62.5 but since it’s an int rounded to 63. Hit DOWN so 1 - 63 so picked 31.5, rounded to 32. hit DOWN again so 1 - 32 and picked 16. You hit DOWN again and it went 1 - 16 so it picked 8. then you hit UP so it went 8 - 16 and picked 12. you hit UP so it went 12 - 16 and picked 14. you hit UP so it went 14 - 16 and picked 15… now you hit UP again instead of telling that it picked right since it picked 14 15 and 16 for you. so you’re lying to the poor computer… but if you hit UP you got 15 - 16… which would pick 15.5 and it rounded it to 15. and if you hit DOWN it would go 15 - 16 and repeat, and up would be 15-15 and stuck… I’m not seeing an error.

What number did you intend because this is what you got from your code…