title: Vending machine repeat menu after option is chosen?
body: <p>Here is my vending machine. I now need to be able to be able to repeat the menu at the end of the switch to allow the user to go back into the vending machine or exit the program.</p>
  
  <p>Would I use a while loop or an if/else statement. I tried nesting the whole thing in a while loop but then it repeated the the purchase option.</p>
  
  <pre><code>        int iNumCrisps = 10;
          int iCrispsBought;
  
          int iNumChocbars = 20;
          int iChocbarsBought;
  
          int iNumSweets = 30;
          int iSweetsBought;
  
          double dTotalMoney = 0;
          int iChoice;
  
  
          {
              //display the choices
              Console.WriteLine("Vending Machine");
              Console.WriteLine("1 - Buy chocbars");
              Console.WriteLine("2 - Buy crisps");
              Console.WriteLine("3 - Buy sweets");
              // get the users choice
              Console.Write("Enter your choice: ");
              iChoice = Convert.ToInt32(Console.ReadLine());
  
              //validate user input
              while (iChoice &lt; 1 || iChoice &gt; 3)
              {
                  Console.Write("Incorrect option. Please Re-Enter: ");
                  iChoice = Convert.ToInt32(Console.ReadLine());
              }
  
  
  
                  switch (iChoice)
                  {
                      case 1: //user has chosen chocbars
                          Console.WriteLine();
                          Console.Write("How many chocbars do you wish to purchase?");
                          iChocbarsBought = Convert.ToInt32(Console.ReadLine());
  
                          iNumChocbars = iNumChocbars - iChocbarsBought;
                          dTotalMoney = dTotalMoney + (iChocbarsBought * 0.25);
                          Console.WriteLine("There are now" + iNumChocbars + " chocbars in the machine");
                          break;
  
                      case 2: //User has chosen crisps
                          Console.WriteLine();
                          Console.Write("How many crisps do you wish to purchase?");
                          iCrispsBought = Convert.ToInt32(Console.ReadLine());
  
                          iNumCrisps = iNumCrisps - iCrispsBought;
                          dTotalMoney = dTotalMoney + (iCrispsBought * 0.30);
                          Console.WriteLine("There are now" + iNumCrisps + " crisps in the machine");
                          break;
  
                      case 3: //user has chosen sweets
                          Console.WriteLine();
                          Console.Write("How many sweets do you wish to purchase?");
                          iSweetsBought = Convert.ToInt32(Console.ReadLine());
                          iNumSweets = iNumSweets - iSweetsBought;
                          dTotalMoney = dTotalMoney + (iSweetsBought * 0.20);
                          Console.WriteLine("There are now " + iNumSweets + " sweets in the machine");
                          break;
                      default:
                          Console.WriteLine("You must enter a number from 1 to 3");
                          break;
                  }// end switch
  
  
  
              //validate user input
              while (iChoice &lt; 1 || iChoice &gt; 3)
              {
                  Console.Write("Incorrect option. Please Re-Enter: ");
                  iChoice = Convert.ToInt32(Console.ReadLine());
              }
  
  
              Console.WriteLine("There is now" + dTotalMoney + "p in the machine");
  
              Console.WriteLine();
              Console.WriteLine("Press any key to close");
              Console.WriteLine();
              Console.ReadKey();
  
          }
      }
  }
  </code></pre>
  
  <p>}</p>