#assign our initial variables for the game
[int]$lowerLimit = 0
[int]$upperLimit = 100
[int]$myGuess = 50
[int]$timesRun = 0
[int]$solved = 0
While ($solved -eq 0){
$queryString = "Is your number " + $myGuess + "? (higher/lower/correct)"
$response = read-host $queryString
switch ($response) {
"higher" {
$lowerLimit = $myGuess
$myGuess = ($lowerLimit + $upperLimit) / 2
$timesRun++
}
"lower" {
$upperLimit = $myGuess
$myGuess = ($lowerLimit + $upperLimit) / 2
$timesRun++
}
"correct" {
$timesRun++
write-host "Hooray, I won in only $timesRun guesses!"
$solved = 1
}
default {
write-host "That is not a valid reply!"
write-host ""
}
}
}