سؤال

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