R
Guess what number im thinking gameport by LanceGary
# Number guessing game for R
# This is a test program in R to demonstrate interactive
# programming and the If and While control structures
# This program must be started using the source() command
NumGuess <- 0 # Initialise this symbol, used to count the number guesses
Uname <- readline("What is your name? ")
cat("Guess a number between 1 and a 100 ", Uname, "\n")
ComNum <- as.integer(runif(1, min = 1, max = 100))
Guess <- as.integer(readline("Enter your guess: "))
NumGuess <- NumGuess + 1
while (ComNum != Guess) {
if (Guess<ComNum) {
cat("Your guess is too low!", "\n")
} else {
cat("Your guess is too high!", "\n")
}
Guess <- as.integer(readline("Please enter a new guess: "))
NumGuess <- NumGuess + 1
}
cat(Uname,", you got it! ", "\n")
cat("It took you ",NumGuess," guesses to guess right.", "\n")