title: Windows forms Random Timed Math quiz c#
body: <p>My problem is that I want to put a max number limit where the user would put a max question of 2 like an example and my program would show random question only 2 times but it keeps generating numbers I think my problem is with changing the textbox to int and where to place it I'm new to windows forms the first button generate random questions the second button should do the same but minus a number of question every time the user clicks I tried a lot <code>operationbox</code> is for the user to choose his operation(+,-,*,/) and the range box is the range of the random numbers.</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication7
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
              rangebox1.Items.Add(&quot;[1,100]&quot;);
              rangebox1.Items.Add(&quot;[1,500]&quot;);
              rangebox1.Items.Add(&quot;[1,1000]&quot;);
              Operationbox1.Items.Add(&quot;+&quot;);
              Operationbox1.Items.Add(&quot;-&quot;);
              Operationbox1.Items.Add(&quot;*&quot;);
              Operationbox1.Items.Add(&quot;/&quot;);
          }
        
          int[] Rand(int v)
          {
  
              Random r = new Random();
          int a = r.Next(1,v);
              int b = r.Next(1,v);
              int[] N = {Math.Max(a,b) , Math.Min(a,b)};
              return N;
          
          }
          void generate()
          {
              int range = 0;
              switch (rangebox1.SelectedIndex)
              { 
                  case 0:
                      range = 100;
                      break;
                  case 1:
                      range = 500;
                          break;
                  case 2:
                      range = 1000;
                          break;
                  default:
                      MessageBox.Show(&quot;Put a range !&quot;);
                      break;
              
              }
              int[] numbers = Rand(range);
              switch (Operationbox1.SelectedIndex)
              { 
                  case 0:
                      questionlbl1.Text = string.Format(&quot;{0} + {1} =&quot;,numbers[0],numbers[1]);
                      break;
                  case 1:
                      questionlbl1.Text = string.Format(&quot;{0} - {1} =&quot; , numbers[0], numbers[1]);
                      break;
                  case 2:
                      questionlbl1.Text = string.Format(&quot;{0} * {1} =&quot; , numbers[0], numbers[1]);
                      break;
                  case 3:
                      questionlbl1.Text = string.Format(&quot;{0} / {1} =&quot; , numbers[0], numbers[1]);
                      break;
                  default:
                      MessageBox.Show(&quot;Please insert a operation&quot;);
                      break;
              }
          
          }
          void numberquest()
          {
              int numofquestionleft = Convert.ToInt32(numofquest1.Text);
              int r = int.Parse(numofquest1.Text);
              if (numofquestionleft &gt; 0) generate();
              numofquestionleft--;
  
          }
  
          private void genbutton1_Click(object sender, EventArgs e)
          {
              generate();
              
          }
  
        
          private void button1_Click(object sender, EventArgs e)
          {
              numberquest();
          }
      }
  }
  </code></pre>