jeudi 28 septembre 2017

If Statement with multiple OR Values

I'm currently working on a Simple Riddles Game outside of class, and what I want to do is have a statement that will verify what the question is, and if the answer that was put in is correct. Here is the Code I have so far:

private void butt_Submit_Click(object sender, EventArgs e)
        {
            if (lab_Riddle.Text == "What Walks on 4 Legs in the Morning, 2 in the Afternoon and 3 in the Evening?")

                if (TeBo_Ans.Text == "A Man") ;
;             {
                MessageBox.Show("Well Done");
                lab_Riddle.Text = ("I have an Eye but Cannot See- What Am I?");
             }
            if (TeBo_Ans.Text == "Mankind") ;
             {
                MessageBox.Show("Good Words");
                lab_Riddle.Text = ("I have an Eye but Cannot See- What Am I?");
             }
            if (TeBo_Ans.Text == "People") ;
             {
                MessageBox.Show("Yes");
                lab_Riddle.Text = ("I have an Eye but Cannot See- What Am I?");
             }
            if (TeBo_Ans.Text == "A Person") ;
             {
                MessageBox.Show("Exactly");
                lab_Riddle.Text = ("I have an Eye but Cannot See- What Am I?");
             }
            if (TeBo_Ans.Text == "Humankind") ;
             {
                MessageBox.Show("Exactly");
                lab_Riddle.Text = ("I have an Eye but Cannot See- What Am I?");
             }
        } 

Here, lab_Riddle is the label containing the Question, and TeBo_Ans is the textbox the user types the answer into. This code sort of Works, but ideally I'd like to condense it down to something like

If lab_Riddle.Text= [Riddle 1]
 {
  If TeBo_Ans == [a] OR [b] OR [d] 
   {
    MessageBox.Show ("Correct")
    lab_Riddle.Text [riddle 2]
    }
   Else 
   { 
    MessageBox.Show ("Incorrect")
  }
}

Language is C# if I haven't already said., and vertical lines. This is probably a really long and convoluted way of doing this, but i'm still very new to coding.

Thanks for your help!

Aucun commentaire:

Enregistrer un commentaire