문제

Ok, so I'm new to Visual Basic, not to others. I have an assignment for college and this is probably ahead of the curve, but I decided to do some automated error checking in the program we're writing for an assignment. We haven't covered loops yet, but my "Don't trust the user to not input something they're not supposed to" sense is itching badly. Here's my code:

    Console.WriteLine("What is your marital status?")
    Console.Write("Enter (m)arried, (s)ingle, (d)ivorced, (w)idowed: ")
    maritalStatus = Console.ReadLine()
    Do While maritalStatus IsNot "m" Or maritalStatus IsNot "s" Or maritalStatus IsNot "d" Or maritalStatus IsNot "w"
        Console.WriteLine("Please enter a valid marital status.")
        Console.Write("Enter (m)arried, (s)ingle, (d)ivorced, (w)idowed: ")
        maritalStatus = Console.ReadLine()
    Loop
    Console.Clear()

The good news is if you input anything other that m, s, d, or w it loops back and tells you to enter a valid one. The bad news is it does that even if you put in m, s, d, or w.

My googling patience is growing thin. Any help offered?

도움이 되었습니까?

해결책

Try using "and" instead of "or".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top