title: Create a list, vector or array with 4 cities and a temperature for each city
body: <p>I can't get this program to work properly. We're supposed to through user input create a list, vector or array with 4 cities and a temperature for each city, I've successfully managed to add the cities and the temperature, also we have to keep the temperature between -60 and +60 which I've also successfully done. Last part of the program is that the user is supposed to input a temperature to search for, if the temperature exists for one of the cities it's supposed to write the temperature, the city that has the temperature and the index in the array/vector/list. I've decided to make it into a list as I thought that was easiest (maybe I'm wrong?). I seemingly can't get the linearsearch to work though as it always does the &quot;return -1&quot; part and just says the temperature the user is searching for doesn't exist in any index.</p>
  <p>I've tried switching the names around if there is something I've done wrong there but that either breaks everything or gives the same result. I've tried to change the names and I've tried to get the linearsearch to use other variables to see if I may have mislabeled something but that just breaks the program when it reaches that point in the code. I've also tried to move codeblocks around in order to see if it tries to access it in wrong order but it yields the same result.</p>
  <p>I'm a beginner at programming and I'm really worthless at working with several classes and constructors but since this is homework I kinda have to. Also the ToSpring(); that we must have in the code, everyone in the course just did what I did since it seems obsolete? Maybe there is something there I'm doing wrong? Maybe the constructor itself but I've taken it from our course literature? Not sure if it's valid info but I use Visual Studio 2022.</p>
  <p>I hope the Swedish doesn't throw everyone off too much, I've tried to add comments in English to describe what it's supposed to be or do. &quot;Stad&quot; means city in Swedish btw if that clears up or helps in any way since that is a large part of the constructor and class?</p>
  <pre><code>class Stad
  {
      public string name;
      public int temp;
  
      public Stad()
      {
      }
  
      public Stad(string name, int temp)
      {
          this.name = name;
          this.temp = temp;
      }
  
      public string Name
      {
          get { return name; }
          set { name = value; }
      }
      public int Temp
      {
          get { return temp; }
          set { temp = value; }
      }
      public override string ToString()
      {
          return base.ToString();
      }
  }
  
  
  class Program
  {
  
      static int LinearSearch(List&lt;Stad&gt; myList, int n) // linear search creation
      {
          for (int i = 0; i &lt; Stad.Count; i++)
          {
              if (myList[i].Temp == n)
                  return i;
          }
          return -1;
      }
      static void Main(string[] args)
      {
          List&lt;Stad&gt; myList = new List&lt;Stad&gt;(); // list for cities and temperature
          Stad myStad = new Stad();
  
      Stad_1: // city 1
  
          Console.WriteLine(&quot;Ange stad nummer 1&quot;); // user input for city
          myStad.Name = Console.ReadLine();
          Console.WriteLine(&quot;Ange temperatur för stad nummer 1&quot;); // user input for temp 
          myStad.Temp = Convert.ToInt32(Console.ReadLine());
  
          if (myStad.Temp &gt;= 61) // what happens if temp is higher than 60 degrees
          {
              Console.WriteLine(&quot;Felaktigt värde var god välj en siffra mellan -60 och +60&quot;);
              goto Stad_1;
          }
          else if (myStad.Temp &lt;= -61) // what happens if temp is lower than -60 degrees
          {
              Console.WriteLine(&quot;Felaktigt värde var god välj en siffra mellan -60 och +60&quot;);
              goto Stad_1;
          }
          else
          {
              Console.WriteLine(&quot;Ange stad nummer 2&quot;);
          }
          
      Stad_2: // see city 1 for details
  
          myStad.Name = Console.ReadLine();
          Console.WriteLine(&quot;Ange temperatur för stad nummer 2&quot;);
          myStad.Temp = Convert.ToInt32(Console.ReadLine());
                      if (myStad.Temp &gt;= 61)
          {
              Console.WriteLine(&quot;Felaktigt värde var god välj en siffra mellan -60 och +60&quot;);
              goto Stad_2;
          }
          else if (myStad.Temp &lt;= -61)
          {
              Console.WriteLine(&quot;Felaktigt värde var god välj en siffra mellan -60 och +60&quot;);
              goto Stad_2;
          }
          else
          {
              Console.WriteLine(&quot;Ange stad nummer 3&quot;);
          }
                      
      Stad_3: // see city 1 for details
  
          myStad.Name = Console.ReadLine();
          Console.WriteLine(&quot;Ange temperatur för stad nummer 3&quot;);
          myStad.Temp = Convert.ToInt32(Console.ReadLine());
          if (myStad.Temp &gt;= 61)
          {
              Console.WriteLine(&quot;Felaktigt värde var god välj en siffra mellan -60 och +60&quot;);
              goto Stad_3;
          }
          else if (myStad.Temp &lt;= -61)
          {
              Console.WriteLine(&quot;Felaktigt värde var god välj en siffra mellan -60 och +60&quot;);
              goto Stad_3;
          }
          else
          {
              Console.WriteLine(&quot;Ange stad nummer 4&quot;);
          }
          
      Stad_4: // see city 1 for details
  
          myStad.Name = Console.ReadLine();
          Console.WriteLine(&quot;Ange temperatur för stad nummer 4&quot;);
          myStad.Temp = Convert.ToInt32(Console.ReadLine());
          if (myStad.Temp &gt;= 61)
          {
              Console.WriteLine(&quot;Felaktigt värde var god välj en siffra mellan -60 och +60&quot;);
              goto Stad_4;
          }
          else if (myStad.Temp &lt;= -61)
          {
              Console.WriteLine(&quot;Felaktigt värde var god välj en siffra mellan -60 och +60&quot;);
              goto Stad_4;
          }
          else
          {
              Console.WriteLine(&quot;Tack&quot;);
          }
  
          // what temp to search for in the linear search
  
          Console.Write(&quot;Ange temperatur att söka efter: &quot;);
          string str = Console.ReadLine(); 
          int n = Convert.ToInt32(str);
  
          int list = LinearSearch(myList, n);
  
          // linear search printout
  
          if (list == -1)
              Console.WriteLine(&quot;Temperaturen finns ej&quot;);
          else
              Console.WriteLine(&quot;Staden med temperaturen &quot; + n + &quot; finns på index &quot; + list + &quot; och är &quot; + myList[list].Name);
      }
  }
  </code></pre>