title: I don't knw why my output goes to my last number when it's supposed to go to the number indicated by Target Integer
body: <pre><code>#pragma once
  
  namespace PointerArray {
  
      using namespace System;
      using namespace System::ComponentModel;
      using namespace System::Collections;
      using namespace System::Windows::Forms;
      using namespace System::Data;
      using namespace System::Drawing;
  
      /// &lt;summary&gt;
      /// Summary for Form1
      /// &lt;/summary&gt;
      public ref class Form1 : public System::Windows::Forms::Form
      {
      public:
          Form1(void)
          {
              InitializeComponent();
              //
              //TODO: Add the constructor code here
              //
          }
  
      protected:
          /// &lt;summary&gt;
          /// Clean up any resources being used.
          /// &lt;/summary&gt;
          ~Form1()
          {
              if (components)
              {
                  delete components;
              }
          }
      private: System::Windows::Forms::Label^  label1;
      protected: 
      private: System::Windows::Forms::Label^  label2;
      private: System::Windows::Forms::Label^  label3;
      private: System::Windows::Forms::Label^  label4;
      private: System::Windows::Forms::Label^  label5;
      private: System::Windows::Forms::Label^  label6;
      private: System::Windows::Forms::Label^  label7;
      private: System::Windows::Forms::Label^  label8;
      private: System::Windows::Forms::TextBox^  textBox1;
      private: System::Windows::Forms::TextBox^  textBox2;
      private: System::Windows::Forms::TextBox^  textBox3;
      private: System::Windows::Forms::TextBox^  textBox4;
      private: System::Windows::Forms::TextBox^  textBox5;
      private: System::Windows::Forms::TextBox^  textBox6;
      private: System::Windows::Forms::TextBox^  textBox7;
      private: System::Windows::Forms::TextBox^  textBox8;
      private: System::Windows::Forms::TextBox^  textBox9;
      private: System::Windows::Forms::TextBox^  textBox10;
      private: System::Windows::Forms::TextBox^  textBox11;
      private: System::Windows::Forms::TextBox^  textBox12;
      private: System::Windows::Forms::TextBox^  textBox13;
      private: System::Windows::Forms::TextBox^  textBox14;
      private: System::Windows::Forms::TextBox^  textBox15;
      private: System::Windows::Forms::TextBox^  textBox16;
      private: System::Windows::Forms::Label^  label9;
      private: System::Windows::Forms::Label^  label10;
      private: System::Windows::Forms::Button^  btnData;
  
      private: System::Windows::Forms::Button^  btnSort;
      private: System::Windows::Forms::Button^  btnSearch;
      private: System::Windows::Forms::Label^  label11;
      private: System::Windows::Forms::TextBox^  txtTarget;
  
      private:
          /// &lt;summary&gt;
          /// Required designer variable.
          /// &lt;/summary&gt;
          System::ComponentModel::Container ^components;
  
  #pragma region Windows Form Designer generated code
          /// &lt;summary&gt;
          /// Required method for Designer support - do not modify
          /// the contents of this method with the code editor.
          /// &lt;/summary&gt;
          void InitializeComponent(void)
          {
              this-&gt;label1 = (gcnew System::Windows::Forms::Label());
              this-&gt;label2 = (gcnew System::Windows::Forms::Label());
              this-&gt;label3 = (gcnew System::Windows::Forms::Label());
              this-&gt;label4 = (gcnew System::Windows::Forms::Label());
              this-&gt;label5 = (gcnew System::Windows::Forms::Label());
              this-&gt;label6 = (gcnew System::Windows::Forms::Label());
              this-&gt;label7 = (gcnew System::Windows::Forms::Label());
              this-&gt;label8 = (gcnew System::Windows::Forms::Label());
              this-&gt;textBox1 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox2 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox3 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox4 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox5 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox6 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox7 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox8 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox9 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox10 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox11 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox12 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox13 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox14 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox15 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;textBox16 = (gcnew System::Windows::Forms::TextBox());
              this-&gt;label9 = (gcnew System::Windows::Forms::Label());
              this-&gt;label10 = (gcnew System::Windows::Forms::Label());
              this-&gt;btnData = (gcnew System::Windows::Forms::Button());
              this-&gt;btnSort = (gcnew System::Windows::Forms::Button());
              this-&gt;btnSearch = (gcnew System::Windows::Forms::Button());
              this-&gt;label11 = (gcnew System::Windows::Forms::Label());
              this-&gt;txtTarget = (gcnew System::Windows::Forms::TextBox());
              this-&gt;SuspendLayout();
              // 
              // label1
              // 
              this-&gt;label1-&gt;AutoSize = true;
              this-&gt;label1-&gt;Location = System::Drawing::Point(335, 55);
              this-&gt;label1-&gt;Name = L"label1";
              this-&gt;label1-&gt;Size = System::Drawing::Size(35, 13);
              this-&gt;label1-&gt;TabIndex = 0;
              this-&gt;label1-&gt;Text = L"label1";
              // 
              // label2
              // 
              this-&gt;label2-&gt;AutoSize = true;
              this-&gt;label2-&gt;Location = System::Drawing::Point(335, 91);
              this-&gt;label2-&gt;Name = L"label2";
              this-&gt;label2-&gt;Size = System::Drawing::Size(35, 13);
              this-&gt;label2-&gt;TabIndex = 1;
              this-&gt;label2-&gt;Text = L"label2";
              // 
              // label3
              // 
              this-&gt;label3-&gt;AutoSize = true;
              this-&gt;label3-&gt;Location = System::Drawing::Point(335, 123);
              this-&gt;label3-&gt;Name = L"label3";
              this-&gt;label3-&gt;Size = System::Drawing::Size(35, 13);
              this-&gt;label3-&gt;TabIndex = 2;
              this-&gt;label3-&gt;Text = L"label3";
              // 
              // label4
              // 
              this-&gt;label4-&gt;AutoSize = true;
              this-&gt;label4-&gt;Location = System::Drawing::Point(335, 155);
              this-&gt;label4-&gt;Name = L"label4";
              this-&gt;label4-&gt;Size = System::Drawing::Size(35, 13);
              this-&gt;label4-&gt;TabIndex = 3;
              this-&gt;label4-&gt;Text = L"label4";
              // 
              // label5
              // 
              this-&gt;label5-&gt;AutoSize = true;
              this-&gt;label5-&gt;Location = System::Drawing::Point(335, 188);
              this-&gt;label5-&gt;Name = L"label5";
              this-&gt;label5-&gt;Size = System::Drawing::Size(35, 13);
              this-&gt;label5-&gt;TabIndex = 4;
              this-&gt;label5-&gt;Text = L"label5";
              // 
              // label6
              // 
              this-&gt;label6-&gt;AutoSize = true;
              this-&gt;label6-&gt;Location = System::Drawing::Point(335, 221);
              this-&gt;label6-&gt;Name = L"label6";
              this-&gt;label6-&gt;Size = System::Drawing::Size(35, 13);
              this-&gt;label6-&gt;TabIndex = 5;
              this-&gt;label6-&gt;Text = L"label6";
              // 
              // label7
              // 
              this-&gt;label7-&gt;AutoSize = true;
              this-&gt;label7-&gt;Location = System::Drawing::Point(335, 254);
              this-&gt;label7-&gt;Name = L"label7";
              this-&gt;label7-&gt;Size = System::Drawing::Size(35, 13);
              this-&gt;label7-&gt;TabIndex = 6;
              this-&gt;label7-&gt;Text = L"label7";
              // 
              // label8
              // 
              this-&gt;label8-&gt;AutoSize = true;
              this-&gt;label8-&gt;Location = System::Drawing::Point(335, 290);
              this-&gt;label8-&gt;Name = L"label8";
              this-&gt;label8-&gt;Size = System::Drawing::Size(35, 13);
              this-&gt;label8-&gt;TabIndex = 7;
              this-&gt;label8-&gt;Text = L"label8";
              // 
              // textBox1
              // 
              this-&gt;textBox1-&gt;Location = System::Drawing::Point(229, 52);
              this-&gt;textBox1-&gt;Name = L"textBox1";
              this-&gt;textBox1-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox1-&gt;TabIndex = 8;
              // 
              // textBox2
              // 
              this-&gt;textBox2-&gt;Location = System::Drawing::Point(229, 88);
              this-&gt;textBox2-&gt;Name = L"textBox2";
              this-&gt;textBox2-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox2-&gt;TabIndex = 9;
              // 
              // textBox3
              // 
              this-&gt;textBox3-&gt;Location = System::Drawing::Point(229, 120);
              this-&gt;textBox3-&gt;Name = L"textBox3";
              this-&gt;textBox3-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox3-&gt;TabIndex = 10;
              // 
              // textBox4
              // 
              this-&gt;textBox4-&gt;Location = System::Drawing::Point(229, 155);
              this-&gt;textBox4-&gt;Name = L"textBox4";
              this-&gt;textBox4-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox4-&gt;TabIndex = 11;
              // 
              // textBox5
              // 
              this-&gt;textBox5-&gt;Location = System::Drawing::Point(229, 185);
              this-&gt;textBox5-&gt;Name = L"textBox5";
              this-&gt;textBox5-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox5-&gt;TabIndex = 12;
              // 
              // textBox6
              // 
              this-&gt;textBox6-&gt;Location = System::Drawing::Point(229, 218);
              this-&gt;textBox6-&gt;Name = L"textBox6";
              this-&gt;textBox6-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox6-&gt;TabIndex = 13;
              // 
              // textBox7
              // 
              this-&gt;textBox7-&gt;Location = System::Drawing::Point(229, 251);
              this-&gt;textBox7-&gt;Name = L"textBox7";
              this-&gt;textBox7-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox7-&gt;TabIndex = 14;
              // 
              // textBox8
              // 
              this-&gt;textBox8-&gt;Location = System::Drawing::Point(229, 283);
              this-&gt;textBox8-&gt;Name = L"textBox8";
              this-&gt;textBox8-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox8-&gt;TabIndex = 15;
              // 
              // textBox9
              // 
              this-&gt;textBox9-&gt;Location = System::Drawing::Point(30, 52);
              this-&gt;textBox9-&gt;Name = L"textBox9";
              this-&gt;textBox9-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox9-&gt;TabIndex = 23;
              // 
              // textBox10
              // 
              this-&gt;textBox10-&gt;Location = System::Drawing::Point(30, 85);
              this-&gt;textBox10-&gt;Name = L"textBox10";
              this-&gt;textBox10-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox10-&gt;TabIndex = 22;
              // 
              // textBox11
              // 
              this-&gt;textBox11-&gt;Location = System::Drawing::Point(30, 120);
              this-&gt;textBox11-&gt;Name = L"textBox11";
              this-&gt;textBox11-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox11-&gt;TabIndex = 21;
              // 
              // textBox12
              // 
              this-&gt;textBox12-&gt;Location = System::Drawing::Point(30, 155);
              this-&gt;textBox12-&gt;Name = L"textBox12";
              this-&gt;textBox12-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox12-&gt;TabIndex = 20;
              // 
              // textBox13
              // 
              this-&gt;textBox13-&gt;Location = System::Drawing::Point(30, 185);
              this-&gt;textBox13-&gt;Name = L"textBox13";
              this-&gt;textBox13-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox13-&gt;TabIndex = 19;
              // 
              // textBox14
              // 
              this-&gt;textBox14-&gt;Location = System::Drawing::Point(30, 218);
              this-&gt;textBox14-&gt;Name = L"textBox14";
              this-&gt;textBox14-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox14-&gt;TabIndex = 18;
              // 
              // textBox15
              // 
              this-&gt;textBox15-&gt;Location = System::Drawing::Point(30, 251);
              this-&gt;textBox15-&gt;Name = L"textBox15";
              this-&gt;textBox15-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox15-&gt;TabIndex = 17;
              // 
              // textBox16
              // 
              this-&gt;textBox16-&gt;Location = System::Drawing::Point(30, 283);
              this-&gt;textBox16-&gt;Name = L"textBox16";
              this-&gt;textBox16-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;textBox16-&gt;TabIndex = 16;
              // 
              // label9
              // 
              this-&gt;label9-&gt;AutoSize = true;
              this-&gt;label9-&gt;Location = System::Drawing::Point(52, 24);
              this-&gt;label9-&gt;Name = L"label9";
              this-&gt;label9-&gt;Size = System::Drawing::Size(67, 13);
              this-&gt;label9-&gt;TabIndex = 24;
              this-&gt;label9-&gt;Text = L"Pointer Array";
              // 
              // label10
              // 
              this-&gt;label10-&gt;AutoSize = true;
              this-&gt;label10-&gt;Location = System::Drawing::Point(247, 24);
              this-&gt;label10-&gt;Name = L"label10";
              this-&gt;label10-&gt;Size = System::Drawing::Size(57, 13);
              this-&gt;label10-&gt;TabIndex = 25;
              this-&gt;label10-&gt;Text = L"Data Array";
              // 
              // btnData
              // 
              this-&gt;btnData-&gt;Location = System::Drawing::Point(31, 391);
              this-&gt;btnData-&gt;Name = L"btnData";
              this-&gt;btnData-&gt;Size = System::Drawing::Size(75, 23);
              this-&gt;btnData-&gt;TabIndex = 26;
              this-&gt;btnData-&gt;Text = L"Data";
              this-&gt;btnData-&gt;UseVisualStyleBackColor = true;
              this-&gt;btnData-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::btnData_Click);
              // 
              // btnSort
              // 
              this-&gt;btnSort-&gt;Location = System::Drawing::Point(146, 391);
              this-&gt;btnSort-&gt;Name = L"btnSort";
              this-&gt;btnSort-&gt;Size = System::Drawing::Size(75, 23);
              this-&gt;btnSort-&gt;TabIndex = 27;
              this-&gt;btnSort-&gt;Text = L"Sort";
              this-&gt;btnSort-&gt;UseVisualStyleBackColor = true;
              this-&gt;btnSort-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::btnSort_Click);
              // 
              // btnSearch
              // 
              this-&gt;btnSearch-&gt;Location = System::Drawing::Point(255, 391);
              this-&gt;btnSearch-&gt;Name = L"btnSearch";
              this-&gt;btnSearch-&gt;Size = System::Drawing::Size(75, 23);
              this-&gt;btnSearch-&gt;TabIndex = 28;
              this-&gt;btnSearch-&gt;Text = L"Search";
              this-&gt;btnSearch-&gt;UseVisualStyleBackColor = true;
              this-&gt;btnSearch-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::btnSearch_Click);
              // 
              // label11
              // 
              this-&gt;label11-&gt;AutoSize = true;
              this-&gt;label11-&gt;Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                  static_cast&lt;System::Byte&gt;(0)));
              this-&gt;label11-&gt;Location = System::Drawing::Point(27, 334);
              this-&gt;label11-&gt;Name = L"label11";
              this-&gt;label11-&gt;Size = System::Drawing::Size(110, 20);
              this-&gt;label11-&gt;TabIndex = 29;
              this-&gt;label11-&gt;Text = L"Target Integer";
              // 
              // txtTarget
              // 
              this-&gt;txtTarget-&gt;Location = System::Drawing::Point(143, 336);
              this-&gt;txtTarget-&gt;Name = L"txtTarget";
              this-&gt;txtTarget-&gt;Size = System::Drawing::Size(100, 20);
              this-&gt;txtTarget-&gt;TabIndex = 30;
              // 
              // Form1
              // 
              this-&gt;AutoScaleDimensions = System::Drawing::SizeF(6, 13);
              this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
              this-&gt;ClientSize = System::Drawing::Size(467, 641);
              this-&gt;Controls-&gt;Add(this-&gt;txtTarget);
              this-&gt;Controls-&gt;Add(this-&gt;label11);
              this-&gt;Controls-&gt;Add(this-&gt;btnSearch);
              this-&gt;Controls-&gt;Add(this-&gt;btnSort);
              this-&gt;Controls-&gt;Add(this-&gt;btnData);
              this-&gt;Controls-&gt;Add(this-&gt;label10);
              this-&gt;Controls-&gt;Add(this-&gt;label9);
              this-&gt;Controls-&gt;Add(this-&gt;textBox9);
              this-&gt;Controls-&gt;Add(this-&gt;textBox10);
              this-&gt;Controls-&gt;Add(this-&gt;textBox11);
              this-&gt;Controls-&gt;Add(this-&gt;textBox12);
              this-&gt;Controls-&gt;Add(this-&gt;textBox13);
              this-&gt;Controls-&gt;Add(this-&gt;textBox14);
              this-&gt;Controls-&gt;Add(this-&gt;textBox15);
              this-&gt;Controls-&gt;Add(this-&gt;textBox16);
              this-&gt;Controls-&gt;Add(this-&gt;textBox8);
              this-&gt;Controls-&gt;Add(this-&gt;textBox7);
              this-&gt;Controls-&gt;Add(this-&gt;textBox6);
              this-&gt;Controls-&gt;Add(this-&gt;textBox5);
              this-&gt;Controls-&gt;Add(this-&gt;textBox4);
              this-&gt;Controls-&gt;Add(this-&gt;textBox3);
              this-&gt;Controls-&gt;Add(this-&gt;textBox2);
              this-&gt;Controls-&gt;Add(this-&gt;textBox1);
              this-&gt;Controls-&gt;Add(this-&gt;label8);
              this-&gt;Controls-&gt;Add(this-&gt;label7);
              this-&gt;Controls-&gt;Add(this-&gt;label6);
              this-&gt;Controls-&gt;Add(this-&gt;label5);
              this-&gt;Controls-&gt;Add(this-&gt;label4);
              this-&gt;Controls-&gt;Add(this-&gt;label3);
              this-&gt;Controls-&gt;Add(this-&gt;label2);
              this-&gt;Controls-&gt;Add(this-&gt;label1);
              this-&gt;Name = L"Form1";
              this-&gt;Text = L"Pointer Array Program";
              this-&gt;Load += gcnew System::EventHandler(this, &amp;Form1::Form1_Load);
              this-&gt;ResumeLayout(false);
              this-&gt;PerformLayout();
  
          }
  #pragma endregion
          int* arr;
          int** ptr;
          Graphics^ g;
          Pen^ blackPen; 
          private: String^ strTarget;
  
  
  private: void swap(int** a, int** b)
  {
      int* temp;
      temp = *a;
      *a = *b;
      *b = temp;
  }
  
  
  private: void displayPtr()
  {
      // Display ptr values in textBox9 - textBox16
      textBox9-&gt;Text = ((int) ptr[0]).ToString();
      textBox10-&gt;Text = ((int) ptr[1]).ToString();
      textBox11-&gt;Text = ((int) ptr[2]).ToString();
      textBox12-&gt;Text = ((int) ptr[3]).ToString();
      textBox13-&gt;Text = ((int) ptr[4]).ToString();
      textBox14-&gt;Text = ((int) ptr[5]).ToString();
      textBox15-&gt;Text = ((int) ptr[6]).ToString();
      textBox16-&gt;Text = ((int) ptr[7]).ToString();
  
      // Assigns textBox values to corresponding labels
      label1-&gt;Text = ((int) ptr[0]).ToString();
      label2-&gt;Text = ((int) ptr[1]).ToString();
      label3-&gt;Text = ((int) ptr[2]).ToString();
      label4-&gt;Text = ((int) ptr[3]).ToString();
      label5-&gt;Text = ((int) ptr[4]).ToString();
      label6-&gt;Text = ((int) ptr[5]).ToString();
      label7-&gt;Text = ((int) ptr[6]).ToString();
      label8-&gt;Text = ((int) ptr[7]).ToString();
  }
  
  
  private: void drawLines()
  {
      // Calculate start points (ptrX, ptrY)
      int ptrX = textBox9-&gt;Location.X + textBox9-&gt;Width;
      int ptrY = textBox9-&gt;Location.Y + textBox9-&gt;Height/2;
  
      // Calculate end point (arrX)
      int arrX = textBox1-&gt;Location.X;
      int arrY;
      int startY = textBox1-&gt;Location.Y + textBox1-&gt;Height/2;
      // Refresh the form and draw lines 
      this-&gt;Refresh();
      for (int i = 0; i &lt; 8; i++)
      {
          arrY = startY + ((ptr[i] - &amp;(arr[0])) * 32);
          g-&gt;DrawLine(blackPen, ptrX, ptrY, arrX, arrY);
          ptrY += 32;
      }
  }
  
  private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
               arr = new int[8];
               ptr = new int*[8];
               g = this-&gt;CreateGraphics();
               blackPen = gcnew System::Drawing::Pen(Color::Black);
               btnSort-&gt;Enabled = false;
               }
  
  private: System::Void btnData_Click(System::Object^  sender, System::EventArgs^  e) {
               // Declare Variables and Create Random Number Generator
               int i; // Loop Control Variable
               Random^ randomNumber;
               DateTime now = DateTime::Now;
               randomNumber = gcnew Random(now.Millisecond);
  
               // Assign random numbers to arr
               for (i = 0; i &lt; 8; i++) 
                   arr[i] = randomNumber-&gt;Next(0, 100);
  
               // Display arr values in textBox1 - textBox8
               textBox1-&gt;Text = arr[0].ToString();
               textBox2-&gt;Text = arr[1].ToString();
               textBox3-&gt;Text = arr[2].ToString();
               textBox4-&gt;Text = arr[3].ToString();
               textBox5-&gt;Text = arr[4].ToString();
               textBox6-&gt;Text = arr[5].ToString();
               textBox7-&gt;Text = arr[6].ToString();
               textBox8-&gt;Text = arr[7].ToString();
  
               // Assign element addresses to ptr
               for (int i = 0; i &lt; 8; i++) ptr[i] = &amp;arr[i];
  
  
               // Display the pointer array values
               displayPtr();
  
               // Draw lines connecting the pointer and data arrays
               drawLines();
  
               // Turn on Sort Button
               btnSort-&gt;Enabled = true;
           }
  private: System::Void btnSort_Click(System::Object^  sender, System::EventArgs^  e) {
               // Declare Variables
               String^ output = "";
               int i, j;
               int arrTotal;
               // Bubble sort the ptr array
               for (i = 0; i &lt; 7; i++)
                   for (j = 0; j &lt; 7; j++)
                       if (*ptr[j] &gt; *ptr[j+1])
                           swap(&amp;(ptr[j]), &amp;(ptr[j+1]));
  
               // Display pointers with their new address contents
               displayPtr();
               // Concatenate values in sorted order onto output String
               for (i = 0; i &lt; 8; i++) output += (*ptr[i]).ToString() + "\r\n";
               // Draw lines connecting pointer array and data array
               drawLines();
               // Display sorted data in MessageBox
  
               arrTotal = arr[0] + arr[1] + arr[2] + arr[3] + arr[4] + arr[5] + arr[6] + arr[7];
               MessageBox::Show(output, "Sorted Data");
               MessageBox::Show("Sorted Data Sum = " + arrTotal.ToString());
  
               // Draw lines again after MessageBox is closed
               drawLines();
           }
  
  private: System::Void btnSearch_Click(System::Object^  sender, System::EventArgs^  e) {
               // Declare and Initalize Variables
               String^ output = "";
               int i; 
               bool found = false;
               // Read the Target
  </code></pre>
  
  <p>Error here -------------------------------------------------------------</p>
  
  <p>I have no idea why my for loop jumps to the end when it's supposed to go to the number that the user inputs into my txtTarget textBox (says "Enter Integer") I'm not sure how to fix this problem and as far as I can tell my loop makes sense but I'm not sure any and all help is appreciated</p>
  
  <pre><code>             for (i = 0; i &lt; 8; i++) output = (*ptr[i]).ToString(); + "\r\n";
               MessageBox::Show(output-&gt;ToString());
               MessageBox::Show(output, "Target Found "); 
           }
  };
  }
  </code></pre>