Try to search your question here, if you can't find : Ask Any Question Now ?

Simple number games in R Studio for beginners

HomeCategory: stackoverflowSimple number games in R Studio for beginners
Avatarwillson asked 4 weeks ago

I am trying to write a simple number game in R studio. I pick a random number and see if it matches the user’s number input. If it does, “Bingo” will appear and if it does not, “Higher”, “Lower” or “You are so close” appears.

However, I keep getting the error message:

Error: unexpected ‘}’ in ” }” and Warning message: NAs introduced by coercion

nonnegative <- function (x) {
  if (x < 0) {
    print (x*-1)
  } else {
    print (x)
  }
}

guessnumber <- function (guess, Rs_number) {
  if (nonnegative (guess - Rs_number) < 10) {
    print ("You are so close")
  } else (guess == Rs_number) {
    print ('Bingo"')
  } else (guess > Rs_number) {
    print("Lower")
  } else {
    print ("Higher")
  } 

}

guess <- as.numeric(readline(prompt="Guess: "))
Rs_number <- sample(1:100, 1)
guessnumber <- function (guess, Rs_number) 
1 Answers
Best Answer
AvatarJyoti answered 4 weeks ago
Your Answer

15 + 18 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com