Slide 9.5: The switch statement
Slide 9.7: Looping
Home

The switch Statement (Cont.)

 private void Start_Click( object sender, EventArgs e ) {
   int firstNum, secondNum;
   Random rnd = new Random( );
   firstNum   = rnd.Next( 0, 100 );
   secondNum  = rnd.Next( 0, 100 );
   x.Text     = firstNum.ToString( );
   y.Text     = secondNum.ToString( );
 }

 private void OK_Click( object sender, EventArgs e ) {
   switch ( int.Parse(z.Text) == int.Parse(x.Text) + int.Parse(y.Text) ) { 
     case true:
       display.Text  = "Correct";
       image.Visible = true;
       break;
     default:
       display.Text  = "Incorrect";
       image.Visible = false;
       break;
   }
 }
 private void Next_Click( object sender, EventArgs e ) {
   z.Text       = "";
   display.Text = "";
   Start_Click( sender, e );
 }