If Else-question
BlitzMax Forums/BlitzMax Beginners Area/If Else-question
| ||
Hi. New to the forum, since I bought BlitzMax a few days ago. I've got a pretty simple question that I can't seem to find an answer. I blaim the lack of intelligent stimulus for almost a year that I can't seem to figure out the solution to a problem that I solved all by myself about two years ago. I know how to use If else-statements with exact numbers or like if the number is between three and five, but I don't seem to be able to do it with words. Here's what I've come up with so far. name=Byte(Input("What is thy name? ") ) If name = Walter Print "Of course it's you" Else Print "Not the one I'm looking for" EndIf The code should ask, if that one name is the name the user wrote, but with any other name it should print "not the one I'm looking for". Thanks in advance Mindfield |
| ||
You need to use strings. e.g. Local name:String=Input("What is thy name? ") If name="Walter" Print "Of course it's you" Else Print "Not the one I'm looking for" EndIf Note that when you are asking `if name="Walter"`, the user would have had to enter the exact name with an uppercase W. To get around that you can then start to use something like Upper$() or whatever the BlitzMax equivalent is, to convert the input to all uppercase or lowercase. Then you can just check for the upper or lowercase version. |
| ||
AngelDaniel fixed you up. Here is some food for thought.... Replace the second line with.... If name.ToUpper() = "WALTER" The code will still work, but now you can type in all caps, all lower case, mix the case, etc. Casing (upper or lower) is a great way to handle input when case is unimportant. Top |
| ||
It didn't work while replacing the second line with If name.ToUpper() = "WALTER" . It kept wanting the word as "Walter". |
| ||
This works for me: Local name:String=Input("What is thy name? ") If Upper(name)="WALTER" Print "Of course it's you" Else Print "Not the one I'm looking for" EndIf |