none
negative form of "if"? RRS feed

  • General discussion

  • hello people, I'm actually making a yes/no questions apps ( i'm new to small basic) but i'd like to know how i could detect if the user doesn't answer yes or no.

    i already have the detections for yes and no, which are:

    answer = TextWindow.Read()

    If(answer = "yes")Then
      TextWindow.WriteLine("ok good")
    Endif
    If(answer = "no")Then
      TextWindow.WriteLine("ok too bad")
    Endif

    but i want to know how to detect if the user writes random stuff.

    I tried:

    If(!answer = "yes" Or "no")Then
    TextWindow.WriteLine("What?? Answer with yes or no!!")
    Endif

    But it didn't work :S ( i added a "!" at begining of the (),  just like in PAWN scripting but looks like it doesnt work :\)

    How could i do it? thanks

     

    Wednesday, February 9, 2011 11:28 PM

All replies

  • nvm i found a fix XD this: If(answer = "no")Then TextWindow.WriteLine("Ok Too bad") ElseIf(answer = "yes")Then TextWindow.WriteLine("Ok good") Else TextWindow.WriteLine("What?? Answer with yes or no!!") Endif now it works :D
    Thursday, February 10, 2011 12:40 AM
  • Hey Pmk1,

    I would do this:

    TextWindow.WriteLine("Are you older than 18?") 'Question
    answer = TextWindow.Read()

    Text.ConvertToLowerCase(answer)

    If (answer = "yes") Then
      TextWindow.WriteLine("Good")
    ElseIf (answer = "no") Then
       TextWindow.WriteLine("Not Good")
    Else
       TextWindow.WriteLine("I don't understand")
    Endif

    WARNING: For some reason Text.ConvertToLowerCase doesn't seem to work if I type NO I get "I don't understand". Any ideas anyone?

    Apart from that this is the basic structure of what I think you need.

    Thursday, February 10, 2011 12:49 AM
  • Hey Pmk1,

    I would do this:

    TextWindow.WriteLine("Are you older than 18?") 'Question
    answer = TextWindow.Read()

    Text.ConvertToLowerCase(answer)

    If (answer = "yes") Then
      TextWindow.WriteLine("Good")
    ElseIf (answer = "no") Then
       TextWindow.WriteLine("Not Good")
    Else
       TextWindow.WriteLine("I don't understand")
    Endif

    WARNING: For some reason Text.ConvertToLowerCase doesn't seem to work if I type NO I get "I don't understand". Any ideas anyone?

    Apart from that this is the basic structure of what I think you need.

    Where you coded "Text.ConvertToLowerCase(answer)" needs to be changed to "answer = Text.ConvertToLowerCase(answer)", so that you can set the value of the variable answer

    ~~AirWaves!!~~
    Thursday, February 10, 2011 12:52 AM
  • Haha thanks AirWaves.

    Pmk1,

    I would also use Text.ConverToLowerCase as written in AirWaves post because as far as I understand no, No, nO and NO are all different answers, and would become an invalid answer.

     

    Thursday, February 10, 2011 12:56 AM
  • You can use

    i = Math.GetRandomNumber(2)
    If i <> 1 Then 'Use <> for some places
        TextWindow.WriteLine("your number is 2")
    Else
        TextWindow.WriteLine("your number is 1")
    EndIf


    ~~AirWaves!!~~
    Friday, February 11, 2011 8:52 PM