title: c++ remove multiples of a given integer from a linked list
body: <p>sorry for my ignorance but i'm both new here and on C++. I'm studying linked list and there is an exercise where i have to write a function that takes in input a list of integers and integer n. The function has to remove from the list all the nodes with a multiple of n and return the list. I thought i did it right but my code doesn't output anything. Could someone explain me why? Thank you all!</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct list{
      int val;
      list* next;
  };
  typedef list* ptr_list;
  
  ptr_list new_node(ptr_list old_node, int value);
  
  ptr_list remove_mult(ptr_list head, int n);
  
  void print_list(ptr_list head);
  
  int main() {
  
      ptr_list head, p1, p2, p3;
      head = new list;
      head-&gt;val = 1;
      p1 = new_node(head, 2);
      p2 = new_node(p1, 3);
      p3 = new_node(p2, 4);
  
      p3-&gt;next = NULL;
  
      remove_mult(head, 2);
      print_list(head);
  
      return(0);
  }
  
  ptr_list new_node(ptr_list old_node, int value)
  {
      old_node-&gt;next = new list;
      old_node-&gt;next-&gt;val = value;
      return old_node-&gt;next;
  }
  
  
  ptr_list remove_mult(ptr_list head, int n){
      ptr_list prev, curr;
      prev = head;
      curr = head-&gt;next;
      while(curr-&gt;next != NULL){
          if((head-&gt;val % n) == 0){
              head = head-&gt;next;
              curr = curr-&gt;next;
          }
          else if((curr-&gt;val % n) == 0){
              ptr_list tmp;
              tmp = prev-&gt;next;
              prev-&gt;next = tmp-&gt;next;
              delete tmp;
          }
          prev = curr;
          curr = curr-&gt;next;
      }
      if((curr-&gt;val % n) == 0){
          prev-&gt;next = NULL;
          delete curr;
      }
      return(head);
  }
  
  void print_list(ptr_list head){
      while ( head != NULL ){
          cout &lt;&lt; head-&gt;val &lt;&lt; " ";
          head = head-&gt;next;
      }
  }
  </code></pre>