title: using methods for program?
body: <p>So I did this hangman game, and it works perfectly fine, the only problem is that I want to use methods to organize everything.</p>
  
  <p>And yes, it is a school project. I tried my best but whenever I try to put a part of the program in a method it's as if I removed a variable and it underlines it in red.</p>
  
  <p>I removed them for now so it's more clear. also, the file I used contained 19 8 letters max words, one on each line.</p>
  
  <p>Can someone tell me how I can incorporate methods without ruining the whole thing? also English isn't my first language plz excuse any mistakes, the code was in french and I translated it for this question. thank you very much. I appreciate your time and effort :)</p>
  
  <pre><code>using System;
  using System.IO;
  
  namespace TP3
  {
      class Program
      {
          public const String Dico = "dico.txt";
  
          public static void Welcome()
          {
              //Mot de bienvenue
              Console.WriteLine("Welcome to hangman !");
          }
  
          public static void Goodbye()
          {
              Console.WriteLine("thx for playing, goodbye!");
          }
  
          public static void Program()
          {
              int SolvedWords= 0;
              string WordToGuess= "";
              int NumberOfLetters ;
              int x = 0;
              int WordTried = 0;
  
              Console.WriteLine("");
              Console.WriteLine("Do you wanna guess a word ? oui or non.");
              Console.WriteLine("you have 8  chances per word.");
              string Answer= Console.ReadLine();
              Answer= Answer.ToLower();
  
              while (Answer== "oui" &amp;&amp; WordTried &lt;19) 
              {
                  const int Lives= 8;
                  int LostLives= 0;
                  int LivesLeft= 8;
                  int LettersGuesed= 0;
                  x += 1;
                  WordTried += 1;
  
                  if (WordTried &lt;= 20 &amp;&amp; WordTried &gt;1) 
                  {
                      Console.WriteLine("Do you wanna guess a word ? oui or non.");
                      Answer= Console.ReadLine();
                      Answer= Answer.ToLower();
                  }
  
                  //Read a word in the file
                  int compteur = 0;
                  string ligne;
                  // Read file and show on the line
                  System.IO.StreamReader file = new System.IO.StreamReader(@"dico.txt");
                  while ((line = file.ReadLine()) != null)
                  {
                      compteur++;
                      if (compteur == x)
                      {
                          WordToGuess= line;
                      }
                  }
                  file.Close();
  
                  char[] table;
                  table = new char[WordToGuess.Length];
                  for (int i = 0; i &lt; table.Length; i++)
                  {
                      table[i] = WordToGuess [i];
                  }
  
                  //change each letter into a *
                  Console.WriteLine("here’s the word to guess : ");
                  string HiddenWord = "********";
                  char[] table2;
                  table2 = new char[WordToGuess.Length];
                  for (int i = 0; i &lt; table2.Length; i++)
                  {
                      table2[i] = HiddenWord[i];
                  }
                  for (int i = 0; i &lt; table2.Length; i++)
                  {
                      Console.Write(table2[i]);
                  }
                  Console.WriteLine("");
  
                  //guess the word
                  while (LettersGuesed&lt; WordToGuess.Length &amp;&amp; LivesLeft&gt; 0)
                  {
                      Console.WriteLine("");
                     /* Console.WriteLine("Devinez une seule Letterdu mot. Ne pas écrire une Letter plus d'une fois de suite. Si c'est le cas, recommencez le jeu.");*/
                      string Letter= Console.ReadLine();
                      Letter= Letter.ToLower();
                      NumberOfLetters  = Letter.Length;
                      char[] table3;
                      table3= new char[NumberOfLetters ];
  
                      for (int i = 0; i &lt; table2.Length; i++)
                      {
                          if (table[i].Equals(Letter[0]))
                          {
                              Table2[i] = Letter[0];
                              LettersGuesed+= 1;
                          }
                      }
  
                      for (int i = 0; i &lt; table2.Length; i++)
                      {
                          Console.Write(table2[i]);
                      }
  
                      if (WordToGuess.IndexOf(Lettre) &lt; 0)
                      {
                          Console.WriteLine("");
                          Console.WriteLine("wrong letter.");
                          LostLives+= 1;
                          LivesLeft= Lives- LostLives;
                          Console.WriteLine("you have " + LivesLeft+ " lives left.");
                      }
  
                      if (WordToGuess.IndexOf(Lettre) &gt;= 0)
                      {
                          Console.WriteLine(" ");
                          Console.WriteLine("right !");
                          Console.WriteLine("you have " + LivesLeft+ " lives left.");
                      }
  
                      if (LettersGuesed== WordToGuess.Length &amp;&amp; LivesLeft&gt; 0)
                      {
                          SolvedWords+= 1;
                          Console.WriteLine(" ");
                          Console.WriteLine("you found the word !");
                          Console.WriteLine("you found " + SolvedWords+ " on" + WordTried + " words so far.");
                      }
  
                      if (LivesLeft== 0)
                      {
                          Console.WriteLine("you couldnt guess the word.");
                          Console.WriteLine("the word was :");
                          for (int i = 0; i &lt; table.Length; i++)
                          {
                              Console.Write(table[i]);
                          }
                          Console.WriteLine(" ");
                          Console.WriteLine("you found " + SolvedWords+ " on" + WordTried + " words so far.");
                      }
  
                      if (WordTried == 19)
                      {
                          Console.WriteLine("no more words to guess.");
                      }
                  }
              }
          }
  
          static void Main(string[] args)
          {
              Welcome();
  
              Programme();
  
              Goodbye();
          }
      }
  }
  </code></pre>