title: C++ Linked List Display All
body: <p>I'm new to C++ and currently experimenting about linked lists and I'm having trouble with displaying the multiple values in my program. The problem is in the DisplayAll function.</p>
  
  <pre><code>    struct node
      {
          string firstname;
          string lastname;
          string phonenumber;
          string dayofbirth;
          string monthofbirth;
          string yearofbirth;
          string age;
          string streetname;
          string city;
          string state;
          string zipcode;
          char ch;
          static int count;
          int count2;
          node* next;
      };
  
      class InfoBook
      {
      private:
          node* head;
          node* current;
          node* temp;
  
      public:
          InfoBook();
  
          void userPromptStatement();
          node* AddNode(node*);
          void DisplayAll();
          //node* SearchNode();
          //void sort(node*, int);
          void UpdateNode();
          //node* DeleteNode(node*);
      };
  
  node* InfoBook::AddNode(nodePtr temp)
  { 
      string firstname;
      string lastname;
      string phonenumber;
      string dayofbirth;
      string monthofbirth;
      string yearofbirth;
      string age;
      string streetname;
      string city;
      string state;
      string zipcode;
      InfoBook ad;
  
         if(head != NULL)
          {
              current = head;
              while(current -&gt; next != NULL)
              {
                  current = current -&gt; next;
              }
              current -&gt; next = new node;
              current -&gt; firstname = temp -&gt; firstname;
              current -&gt; lastname = temp -&gt; lastname;
                       ////code here to add the other values////
              current -&gt; zipcode = temp -&gt; zipcode;
              current -&gt; next -&gt; next = nullptr;
              return current;
              ad.userPromptStatement();
          }
         else
          {
              head = new node;
              head -&gt; firstname = temp -&gt; firstname;
              head -&gt; lastname = temp -&gt; lastname;
                      ////code here to add the other values////
              head -&gt; zipcode = temp -&gt; zipcode;
              head -&gt; next = nullptr;
              return current;
          }
  }
  
      ////////////////////////////////DisplayAll/////////////////////////////////
  
      void InfoBook::DisplayAll()
      {
          current = head;
          int count = 1;
          string firstname;
          string lastname;
          string phonenumber;
          string dayofbirth;
          string monthofbirth;
          string yearofbirth;
          string age;
          string streetname;
          string city;
          string state;
          string zipcode;
  
              if(current == nullptr)
              {
                  cout &lt;&lt; "\n\n\No Record exists.";
              }
                  while(current != NULL)
                  {      ////////The problem is somewhere between here////////
                      cout &lt;&lt; "Record # " &lt;&lt; count &lt;&lt; " : ";
                      cout &lt;&lt; current -&gt; firstname &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; lastname &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; phonenumber &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; dayofbirth &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; monthofbirth &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; yearofbirth &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; age &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; streetname &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; city &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; state &lt;&lt; endl;
                      cout &lt;&lt; current -&gt; zipcode &lt;&lt; endl;
                      cout &lt;&lt;"\n\n\n";
                      current = current -&gt; next;
                      count++;
                  }
      }
                              ///////////////////////////////////////////////
  </code></pre>
  
  <p>The program displays only 'Record # : ' but not the values. Any ideas?</p>
  
  <pre><code>//////////////////added//////////////////////
   node* temp = new node;
   node* current;
   char ch;
   int count2 = 0;
   ad.userPromptStatement();
  
   while(1)
   {
      cin &gt;&gt; ch;
      switch(ch)
      {
          case '1':
              system("cls");
              cout &lt;&lt; "\n\nINSERT RECORD";
                          cout &lt;&lt; "\n\nInput FIRST NAME: ";
                          cin.ignore();
                          getline(cin,firstname,'\n');
  
                          cout &lt;&lt; "\nRecord inserted!";
                      current = ad.AddNode(temp);
                  ad.userPromptStatement();
          break;
  
          case '2':
              system("cls");
              cout &lt;&lt; "\n\nDISPLAY ALL\n\n";
              ad.DisplayAll();
              _getch();
              ad.userPromptStatement();
          break;
  </code></pre>