title: Linked List multiple nodes in C++
body: <p>Meet multiple problems while coding, I want to build a room reservation system with linked list, </p>
  
  <p>I want the user can see the room number in the menu and when the room number is taken, the room number will be deleted from the menu.</p>
  
  <p>Is there anyways to simplified the codes, my codes is very messy, please help thanks</p>
  
  <blockquote>
    <p>1.First I used</p>
  </blockquote>
  
  <pre><code>struct nodes{
       int single_room[5] = {101,102,103,104,105};
       int double_room[4] = {201,202,203,204,205};
    };
  </code></pre>
  
  <blockquote>
    <p>But when I want to compare the Linked List with user input it came out errors</p>
  </blockquote>
  
  <pre><code>  void reservation::UpdateReservation(){
          int x;
          node *current;
          current = head;
          bool found;
          found = false;
          cout &lt;&lt; "Please enter your room number to update your reservation: 
   ";
          cin &gt;&gt; x;
  
          while ((current != NULL) &amp;&amp; (!found))
       {
          if (current -&gt; single_room == x)
              found = true;
  
              else
                  current = current -&gt; link;
        }
      while(found)
     {
          cout &lt;&lt;"The number is exist";
          cout &lt;&lt; endl;
          return found;
         cout &lt;&lt; value;
      }
  
       cout &lt;&lt; "The number is not found";
       cout &lt;&lt; endl;  
      }
  }
  </code></pre>
  
  <blockquote>
    <p>It came up an error with ISO C++ forbids comparison between pointer and integer. 
    After I put a for loop, for the single_room[i], but the current -> single_room[i] is empty..</p>
    
    <p>I've stackoverflowed a lot of questions and found out I can't initialize a linked list, so I used one by one initialize value inside the notes</p>
  </blockquote>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;windows.h&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class reservation{
  
  private:
      struct node
      {
          int single_room;
          int double_room;
          int deluxe_suite;
          int president_suite;
          int room_number;
          string name;
          int phone_number;
          int date;
          int number_of_nights;
          int number_of_pax;
          int time;
          node *link;
      }*head;
  
      public:
          reservation();
          void InitializeValue_single_room(int a);
          void InitializeValue_double_room(int b);
          void InitializeValue_deluxe_suite(int c);
          void InitializeValue_president_suite(int d);
          void menu();
          void Room_size();
          void InsertReservation();
          void UpdateReservation();
  //      void DeleteReservation();
          void DisplayReservation();
          ~reservation();
   };
  
   reservation::reservation()
   {
       head = NULL;
   }
  
   reservation::~reservation()
   {
       node *q;
       if (head == NULL)
       {
          return;
       }
       while (head != NULL)
       {
           q = head-&gt;link;
           delete head;
      head = q;
      }
   }
  
   void reservation::InitializeValue_single_room(int a)
   {
  node *newNode;
  
  newNode = new node;
  newNode -&gt; single_room = a;
  newNode -&gt; link = head;
  head = newNode;
   }
  
   void reservation::InitializeValue_double_room(int b)
   {
       node *newNode;
  
       newNode = new node;
       newNode -&gt; double_room = b;
       newNode -&gt; link = head;
       head = newNode;
   }
  
   void reservation::InitializeValue_deluxe_suite(int c)
   {
  node *newNode;
  
  newNode = new node;
  newNode -&gt; deluxe_suite= c;
  newNode -&gt; link = head;
  head = newNode;
   }
  
   void reservation::InitializeValue_president_suite(int d)
   {
  node *newNode;
  
  newNode = new node;
  newNode -&gt; president_suite = d;
  newNode -&gt; link = head;
  head = newNode;
   }
  
   void reservation::menu()
    {
    cout &lt;&lt;"  1. Book a reservation" &lt;&lt; endl;
    cout &lt;&lt;"  2. Update a reservation" &lt;&lt; endl;
    cout &lt;&lt;"  3. Delete a resevation" &lt;&lt; endl;
    cout &lt;&lt;"  4. Display the reservation" &lt;&lt; endl;
    cout &lt;&lt;"  5. Help" &lt;&lt; endl;
    cout &lt;&lt;"  6. Exit" &lt;&lt; endl &lt;&lt; endl;
  
      cout &lt;&lt; "Please enter here: ";
   }
  </code></pre>
  
  <blockquote>
    <p>But I want to print out the value in the Room_size(), it would print out this
    Sorry not enough reputation to upload an image, I just describe here, it would came out|01704272||1704272||1704272||1704272||
    1704272||1704272||1704272||1704272||1728736||101||102||103||104||105|
    It would print out the numbers which I don't want, I only want 101,102,103,104,105 to view</p>
  </blockquote>
  
  <pre><code>  void reservation::Room_size()
  {
   node guest;
   node *current, *current1;
   current = head;
   current1 = head;
   cout &lt;&lt; "  Single Room: " &lt;&lt; endl;
   cout &lt;&lt; "  ";
   while (current != NULL)
   {
          cout &lt;&lt; current -&gt; single_room;
         current = current -&gt; link;
  
        if(current != NULL)
          cout &lt;&lt; "|" &lt;&lt; "|";
  }
  cout &lt;&lt; "|" &lt;&lt; endl;
  
  cout &lt;&lt; "   Double Room: " &lt;&lt; endl;
  cout &lt;&lt; "   ";
  while (current1 != NULL)
  {
      cout &lt;&lt; current1 -&gt; double_room;
      current1 = current1 -&gt; link;
  
      if(current1 != NULL)
          cout &lt;&lt; "|" &lt;&lt; "|";
  }
  cout &lt;&lt; "|" &lt;&lt; endl;
   }
  
    void reservation::InsertReservation()
   {
     node guest;
     node *current;
     current = head;
     bool found;
     found = false;
     char b;
     int c;
     bool d = true;
     bool f = false;
  
    do{
          ofstream file;
          file.open("Guest info.txt", ios::out|ios::app);
  
          if(!file)
         {
            cout &lt;&lt; "ERROR: File can't open";
            system("pause");
        }
          cout&lt;&lt;"Please enter your Name: ";
          getline(cin,guest.name);
          cout &lt;&lt; endl;
  
          while(!f){
          cout &lt;&lt; "Please enter your phone number: +";
          cin &gt;&gt; guest.phone_number;
          if(guest.phone_number &lt; 10)//|| (cin &gt;&gt; guest.phone_number) &lt; 11)
          {
              cout &lt;&lt; "Wrong input! ";
              f = false;
          }
           else{
  
             f = true;
             cin.ignore();
          }
          cout &lt;&lt; endl;       
   }
      cout &lt;&lt; "Please enter the date you want to book: (20/04): ";
      cin &gt;&gt; guest.date;
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "Please enter the number of nights you want to stay: ";
      cin &gt;&gt; guest.number_of_nights ;
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "Please enter the time you want to check in (24:00 format): ";
      cin &gt;&gt; guest.time;
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "Please enter the number of people you have: ";
      cin &gt;&gt; guest.number_of_pax;
  
  
  
  while(d){
      cout &lt;&lt; "1.Single Room\n2.Double Room \n3.Luxury Suite \n4.President Suite\n\n";
      cout &lt;&lt; "Please select the room you want: ";
      cin &gt;&gt; c;
      if(c==1)
      {
          cout &lt;&lt; "   Rooms that are available: " &lt;&lt; endl;
          cout &lt;&lt; "   Single rooms: " &lt;&lt; endl;
  
                  cout &lt;&lt; "   |" &lt;&lt; guest.single_room &lt;&lt; "|";
  
          cout &lt;&lt; endl &lt;&lt; endl;
          cout &lt;&lt; "Please enter the room number you want to book: ";
          cin &gt;&gt; guest.room_number;
          d = false;
      }else if(c==2)
      {
              cout &lt;&lt; "   Rooms that are available: " &lt;&lt; endl;
              cout &lt;&lt; "   Double rooms: " &lt;&lt; endl;
  
                  cout &lt;&lt; "   |" &lt;&lt; guest.double_room &lt;&lt; "|";
  
          cout &lt;&lt; endl &lt;&lt; endl;
          cout &lt;&lt; "Please enter the room number you want to book: ";
          cin &gt;&gt; guest.room_number;
          d = false;
      }else if(c==3)
      {
          cout &lt;&lt; "   Rooms that are available: " &lt;&lt; endl;
          cout &lt;&lt; "   Luxury Suite: " &lt;&lt; endl;
                  cout &lt;&lt; "   |" &lt;&lt; guest.deluxe_suite &lt;&lt; "|";
  
          cout &lt;&lt; endl &lt;&lt; endl;
          cout &lt;&lt; "Please enter the room number you want to book: ";
          cin &gt;&gt; guest.room_number;
          d = false;
      }else if (c==4)
      {
              cout &lt;&lt; "   Rooms that are available: " &lt;&lt; endl;
              cout &lt;&lt; "   President Suite" &lt;&lt; endl;
                  cout &lt;&lt; "   |" &lt;&lt; guest.president_suite &lt;&lt; "|";
  
          cout &lt;&lt; endl &lt;&lt; endl;
          cout &lt;&lt; "Please enter the room number you want to book: ";
          cin &gt;&gt; guest.room_number;
          d = false;
  
      }else
      {
          cout &lt;&lt; "Wrong input. Please try again";
          d = true;
      }
  }
  
  int e;
  cout &lt;&lt; "Press 1 to Save or 2 to cancel:";
      cout &lt;&lt; endl;
      cin &gt;&gt; e;
  
      if(e==1)
      {
          cout &lt;&lt; endl;
          file &lt;&lt; "Guests info" &lt;&lt; endl;
          cout &lt;&lt; endl;
          file &lt;&lt; "=================================================="&lt;&lt; endl;
  
              file &lt;&lt; endl;
              file &lt;&lt; "Room Number: " &lt;&lt; guest.room_number;
              file &lt;&lt; endl;
              file &lt;&lt; "Name: " &lt;&lt; guest.name &lt;&lt; endl;
              file &lt;&lt; endl;
              file &lt;&lt; "Phone Number: " &lt;&lt; guest.phone_number &lt;&lt; endl;
              file &lt;&lt; endl;
              file &lt;&lt; "Date: " &lt;&lt; guest.date &lt;&lt; endl;
              file &lt;&lt; endl;
              file &lt;&lt; "Number of nights: " &lt;&lt; guest.number_of_nights &lt;&lt; endl;
              file &lt;&lt; endl;
              file &lt;&lt; "Time: " &lt;&lt; guest.time &lt;&lt; endl;
              file &lt;&lt; endl;
              file &lt;&lt; "Number of pax: " &lt;&lt; guest.number_of_pax &lt;&lt; endl;
              file &lt;&lt; endl;
          file &lt;&lt; endl;
          file &lt;&lt; "====================================================" &lt;&lt; endl;
          file.close();
          cout &lt;&lt; "Record Saved " &lt;&lt; endl;
          cout &lt;&lt; "======================================================" &lt;&lt; endl;
      }else
      {
          cout &lt;&lt; "Record was not saved " &lt;&lt; endl;
          cout &lt;&lt; "====================================================" &lt;&lt; endl;
          cout &lt;&lt; endl;
      }
  
    /*        while ((current != NULL) &amp;&amp; (!found))
          {
              if (current -&gt; single_room == (guest.room_number))
                  found = true;
              else
                  current = current -&gt; link;
              while(found)
              {
                  cout &lt;&lt; "ROOM NUMBER FOUND";
                  cout &lt;&lt; endl;
              }   
  
              cout &lt;&lt; "NO";
              cout &lt;&lt; endl;
          }*/
  
  
          cout &lt;&lt; "Enter (Y/y) to input another data or enter (N/n) to Exit";
              cin &gt;&gt; b;
          cout &lt;&lt; "======================================================" &lt;&lt; 
      endl; 
            cout &lt;&lt; endl;
        }while(b == 'y' || b == 'Y');
         if(b =='y'|| b=='Y')
        {
              cin.ignore();
         }
   }
    void reservation::DisplayReservation()
  {
    node *current;
     current = head;
     cout &lt;&lt; " |";
   while (current != NULL)//) &amp;&amp; current-&gt; deluxe_suite &lt;400))
    {
  
      cout &lt;&lt; current -&gt; deluxe_suite;
      current = current -&gt; link;
  
      if(current != NULL)
          cout &lt;&lt; "| "&lt;&lt; "|";
    }
     cout &lt;&lt; "|" &lt;&lt; endl;
  }
  
   int main()
   {
     reservation r;
     r.InitializeValue_single_room(105);
     r.InitializeValue_single_room(104);
     r.InitializeValue_single_room(103);
     r.InitializeValue_single_room(102);
     r.InitializeValue_single_room(101);
  
    r.InitializeValue_double_room(204);
    r.InitializeValue_double_room(203);
    r.InitializeValue_double_room(202);
    r.InitializeValue_double_room(201);
  
  r.InitializeValue_deluxe_suite(303);
  r.InitializeValue_deluxe_suite(302);
  r.InitializeValue_deluxe_suite(301);
  
  r.InitializeValue_president_suite(888);
  r.InitializeValue_president_suite(666);
  
  cout &lt;&lt;"================================================" &lt;&lt; endl &lt;&lt; endl;
  cout &lt;&lt;" Welcome to the Hotel Reservation Application" &lt;&lt; endl &lt;&lt; endl;
  cout &lt;&lt;"================================================" &lt;&lt; endl;
  
  int a;
  cout &lt;&lt; "Please wait while the system is analyzing hte data\n";
  
  cout &lt;&lt; endl;
  cout&lt;&lt;"===================================" &lt;&lt; endl;
  cout &lt;&lt;"            Main Menu   " &lt;&lt; endl &lt;&lt; endl;
  cout &lt;&lt; "   Rooms that are available: " &lt;&lt; endl;
  
  r.Room_size();
  cout &lt;&lt; endl &lt;&lt; endl;
  cout &lt;&lt; "===================================" &lt;&lt; endl;
  r.menu();
  cin &gt;&gt; a;
  if(a == 1)
  {
      system("CLS");
      cout &lt;&lt; "===================================" &lt;&lt; endl;
      cout &lt;&lt; "   BOOK A RESERVATION" &lt;&lt; endl;
      cout &lt;&lt; "===================================" &lt;&lt; endl;
      cin.ignore();
      r.InsertReservation();
  }else if(a == 2)
   {
          system("CLS");
          cout &lt;&lt; "===================================" &lt;&lt; endl;
          cout &lt;&lt; "   UPDATE YOUR RESERVATION" &lt;&lt; endl;
          cout &lt;&lt; "===================================" &lt;&lt; endl;
          cin.ignore();
    //        r.UpdateReservation();
          }else if(a == 4)
         {
          system("CLS");
          cout &lt;&lt;"===================================" &lt;&lt; endl;
          cout &lt;&lt; "   VIEW ALL RESERVATION" &lt;&lt; endl;
          cout &lt;&lt; "===================================" &lt;&lt; endl;
          cin.ignore();
          r.DisplayReservation();
    }
  
      return 0;
  
  }
  </code></pre>