title: function not stopping
body: <p>I'm creating a program to input product that asks for <code>itemName,size,amount,and hour+minute</code> </p>
  
  <p>everything so far looks good, but when I compile and chose menu "1" which is adding item by pushing the data inputted, it ran <code>del()</code> function even though i haven't called it yet and cout <code>"--- Add New Order Success ---";</code> didnt show up</p>
  
  <p>also, when I choose menu "2", it successfully printed <code>"no data available"</code> but didn't return to <code>mainMenu</code> after pressing <code>"enter"</code> key</p>
  
  <p>I'm kinda stuck because I don't know what to fix ,searched the questions list in the forum but nothing coded in c++
  also, my code doesnt show any error which makes me confused</p>
  
  <p>Feel free to point anything I'm doing wrong ,and I'm using doubly linked list with push pop method in <code>C</code> because I don't quite understand using vector which the data are encapsulated in classes.</p>
  
  <p>Much appreciated your help,  Thanks in advance :).</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  #include&lt;iomanip&gt;
  using namespace std;
  #define w setw(2)&lt;&lt;flag&lt;&lt;"|"
  #define f flag++
  #define s cin.sync();cin.clear()
  static int flag;
  
  class receiveDate{
  public:
      int hour;
      int minute;
  };
  
  class item:public receiveDate{
  public:
      int jumlah;
      char namaProduk[20];
      int ukuran;
      class item *prev,*next;
  };
  class item *head=NULL,*curr,*tail;
  
  void clear(){
      int i;
      for(i=0;i&lt;100;i++){
          cout&lt;&lt;endl;
      }
  }
  
  void header(){
      clear();
      int a = 1;
      cout&lt;&lt;"           ";
      for(int i=0;i&lt;=90;i++){
          int b = i%10;
          if(b==0){
              cout&lt;&lt;a;
              a++;
          }else{
              cout&lt;&lt;" ";
          }
      }
      cout&lt;&lt;endl&lt;&lt;"  ";
      for(int i = 0;i&lt;=9;i++){
          printf("1234567890");
      }
      cout&lt;&lt;endl&lt;&lt;"  ";
      for(int i=0;i&lt;=100;i++){
          printf("=");
      }
      cout&lt;&lt;endl;
  }
  
  void pop(){
      class item *temp;
  
      if(head!=NULL){
          if(curr == head)
          {
              head = head-&gt;next;
              free(curr);
              if(head != NULL)
              {
                  head-&gt;prev = NULL;
              }
          }
          else if(curr == tail)
          {
              curr = tail;
              tail = tail-&gt;prev;
              free(curr);
              tail-&gt;next = NULL;
          }
          else
          {
              temp = head;
              while(temp-&gt;next != curr)
              {
                  temp = temp-&gt;next;
              }
              curr-&gt;next-&gt;prev = curr-&gt;prev;
              temp-&gt;next = curr-&gt;next;
              free(curr);
          }
      }
  }
  
  void popall()
  {
      while(head!=NULL)
      {
          curr=head;
          head=head-&gt;next;
          free(curr);
      }
  }
  
  void display(){
      header();
      int i=0;
      curr=head;
      cout&lt;&lt;w&lt;&lt;setw(22)&lt;&lt;"Item Name"&lt;&lt;setw(8)&lt;&lt;"Ukuran"&lt;&lt;setw(4)&lt;&lt;"Jam Pesan"&lt;&lt;endl;f;
      while(curr){
          i++;
          cout&lt;&lt; w &lt;&lt; setw(2) &lt;&lt; i &lt;&lt;setw(20) &lt;&lt; curr-&gt;namaProduk &lt;&lt; setw(8)&lt;&lt;curr-&gt;ukuran &lt;&lt;setw(4) &lt;&lt; curr-&gt;hour &lt;&lt; ":" &lt;&lt; curr-&gt;minute;f;
          curr=curr-&gt;next;
      }
  }
  void push(char namaProduk[],int ukuran,int jumlah,int hour,int minute){
      curr=(class item*)malloc(sizeof(class item));
      class item *temp;
      strcpy(curr-&gt;namaProduk,namaProduk);
      curr-&gt;jumlah=jumlah;
      curr-&gt;ukuran=ukuran;
      curr-&gt;hour=hour;
      curr-&gt;minute=minute;
      if(head==NULL){
          head=tail=curr;
      }else{
          curr-&gt;next=head;
          head-&gt;prev=curr;
          head=curr;
      }
      head-&gt;prev=NULL;
      tail-&gt;next=NULL;
  }
  void add(){
      header();
      flag=1;
      char namaProduk[20];
      int ukuran;
      int jumlah;
      int hour;
      int minute;
      char jenis[10];
      do{
          cout&lt;&lt;w&lt;&lt;"Input nama produk [3-30] : ";f;
          cin&gt;&gt;namaProduk;s;
      }while(strlen(namaProduk)&lt;3 || strlen(namaProduk)&gt;30);
      do{
          cout&lt;&lt;w&lt;&lt;"Input ukuran [1 = kecil, 2 = sedang, 3 = besar] : ";f;
          cin&gt;&gt;ukuran;s;
      }while(ukuran&lt;1||ukuran&gt;3);
      do{
          cout&lt;&lt;w&lt;&lt;"Jumlah item [1 - 999] : ";f;
          cin&gt;&gt;jumlah;s;
      }while(jumlah&lt;1||jumlah&gt;999);
      do{
          cout&lt;&lt;w&lt;&lt;"Jam pesan :";f;
          cin&gt;&gt;hour;s;
      }while(hour&lt;0||hour&gt;24);
      do{
          cout&lt;&lt;w&lt;&lt;"Menit pesan:";f;
          cin&gt;&gt;minute;s;
      }while(minute&lt;0||minute&gt;59);
      push(namaProduk,ukuran,jumlah,hour,minute);
  
      cout&lt;&lt;w&lt;&lt;"--- Add New Order Success ---";
      cin.get();
  }
  
  void del(){
      int tot = 0;
      int pos;
      int qty;
      int i;
      if(head==NULL)
      {
          cout&lt;&lt;"--- There is No Order in The List ---";
      }
      else
      {
          curr = head;
          while(curr)
          {
              tot++;
              curr = curr-&gt;next;
          }
          display();
          do
          {
              cout&lt;&lt;" Input Number of The Order [1.."&lt;&lt; tot&lt;&lt;"]";
              cin&gt;&gt;pos;s;
          }while(pos&lt;1 || pos&gt;tot);
  
          curr = head;
  
          for(i=1;i&lt;pos;i++)
          {
              curr = curr-&gt;next;
          }
          pop();
  
          cout&lt;&lt;endl&lt;&lt;" --- Take Order Success ---";
          cin.get();
      }
  }
  
  void menu(){
      int menu;
      do{
          header();
          flag=1;
          cout&lt;&lt;w&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;setw(57)&lt;&lt;"PROGRAM INVENTARIS MINIMARKET"&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;setw(58)&lt;&lt;"=============================="&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;"     Pilih Menu:"&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;"      1. Add Item"&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;"      2. View Inventory"&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;"      3. Remove order"&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;"      4. Remove all order"&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;"      5. Exit Program"&lt;&lt;endl;f;
          cout&lt;&lt;w&lt;&lt;"      Input Menu: ";f;
          cin&gt;&gt;menu;s;
          cin.sync();cin.clear();
  
          if (menu =1 ){
              add();
          }else if(menu=2){
              display();
          }else if(menu=3){
              del();
          }else if(menu=4){
              popall();
          }else{
              break;
          }
      }while(menu&lt;1||menu&gt;5);
  }
  int main(){   
      menu();
      return 0;
  }
  </code></pre>