title: Generating random number for a Receipt
body: <p>What I want to do is create a simple receipt, which can be created by the user and then displayed, searched by the receipt number, and deleted by receipt number.</p>
  <p>So far I have created a random number which is a set of four numbers. Unfortunately, I can't figure out how to assign it to a new receipt.</p>
  <p>This is the code, no errors are being displayed.</p>
  <pre><code>        #include &lt;iostream&gt;
          #include &lt;stdlib.h&gt;
          #include &lt;ctime&gt;
  
          using namespace std;
  
  
          class cReceipt{
              private:
                  cReceipt *nNext; 
                  int nNumber, articleNum;
              public:
                  char articleName[40];
                  int price, ammound;
                      
              cReceipt(){cout&lt;&lt;&quot;Alocating&quot;&lt;&lt;endl;nNext=NULL;}
              ~cReceipt(){cout&lt;&lt;&quot;Dealocating: &quot;&lt;&lt; articleNum &lt;&lt; &quot; &quot; &lt;&lt; articleName &lt;&lt; &quot; &quot; 
                      &lt;&lt; price &lt;&lt; &quot; &quot; &lt;&lt; ammound &lt;&lt;endl;}
              
              public:
                  void dealokate()
                  {
                      cReceipt *previus,*rightNow;
                      previus=this;
                      rightNow=this-&gt;nNext;
                      
                      cout &lt;&lt;&quot;Dealocation:&quot; &lt;&lt; endl; 
                      if (!rightNow)
                      {
                          cout &lt;&lt;&quot;Nothing to dealocate&quot; &lt;&lt; endl; 
                          return;
                      }
                      
                      while(rightNow)
                      {
                      if (previus!=this)
                          delete previus;
                      previus=rightNow;
                      rightNow=rightNow-&gt;nNext;
                      }
                      
                      delete previus; 
                      this-&gt;nNext=NULL;
                  }
                  
                  void articleGenerator()
                  {
                      for (nNumber = 1; nNumber &lt;= 4; nNumber++) 
                      {
                          articleNum = 0 + rand() % 9;
                          cout &lt;&lt; articleNum;
                      }
                      cout &lt;&lt; &quot;\n&quot;;   
                  }
                  
                  void input()
                  {
                      cReceipt *zadnji, *novi; 
                      
                      zadnji=this;
                      while(zadnji-&gt;nNext)
                      zadnji=zadnji-&gt;nNext;
                      
                      novi = new cReceipt;
                      zadnji-&gt;nNext=novi;
                      
                      cout &lt;&lt; &quot;Items of Receipt: &quot; &lt;&lt; endl;
                      cout &lt;&lt; &quot;Recept number: &quot; &lt;&lt; novi-&gt;articleNum &lt;&lt; endl;
                      cout &lt;&lt; &quot;Article name: &quot;; cin &gt;&gt; novi-&gt;articleName;
                      cout &lt;&lt; &quot;Price:&quot;; cin &gt;&gt; novi-&gt;price;
                      cout &lt;&lt; &quot;Ammound:&quot;; cin &gt;&gt; novi-&gt;ammound;
                  }
                  
                  void output()
                  {
                      cReceipt *rightNow=this-&gt;nNext;
                          
                      while (rightNow)
                      {
                          cout &lt;&lt; &quot;Recept: &quot; &lt;&lt; rightNow-&gt;articleNum &lt;&lt; endl;
                          cout &lt;&lt; &quot;Article name: &quot; &lt;&lt; rightNow-&gt;articleName &lt;&lt; endl;
                          cout &lt;&lt; &quot;Price: &quot; &lt;&lt; rightNow-&gt;price &lt;&lt; endl;
                          cout &lt;&lt; &quot;Ammound: &quot; &lt;&lt; rightNow-&gt;ammound &lt;&lt; endl;
                          cout &lt;&lt; &quot;---&quot; &lt;&lt; endl;
                          rightNow=rightNow-&gt;nNext;
                      }
                  }
          };
  
          int main()
          {
              setlocale(LC_CTYPE, &quot;&quot;);
              
              srand(time(0));
              
              cReceipt cPointer;
                  
              int chojc;
              
              cout &lt;&lt; &quot;Method(articleGenerator) on object(cPointer): &quot;;
              cPointer.articleGenerator();
              
              do
              {
                  cout &lt;&lt; endl;
                  cout &lt;&lt; &quot;=========================&quot; &lt;&lt; endl;
                  cout &lt;&lt; &quot;0. Dealokation&quot; &lt;&lt; endl;
                  cout &lt;&lt; &quot;1. Input.&quot; &lt;&lt; endl;
                  cout &lt;&lt; &quot;2. Output.&quot; &lt;&lt; endl;
                  cout &lt;&lt; &quot;Your choice: &quot;; cin &gt;&gt; chojc;
                  cout &lt;&lt; &quot;=========================&quot; &lt;&lt; endl;
                  
                  switch(chojc)
                  {
                      case 0: 
                          cPointer.dealokate();
                          break;
                      case 1: 
                          cPointer.input();
                          break;
                      case 2: 
                          cPointer.output();
                          break;
                      case 90: 
                          break;  
                  }
              }while(chojc!=90);
              
              system(&quot;PAUSE&quot;);
              return 0;   
          }
  </code></pre>
  <p>EDIT:
  I changed the method to be a type of void to fix the return warning and called it to an object and uploaded the new code.</p>
  <p>Here is a visual illustration of what I am trying to achieve
  [1]: <a href="https://i.stack.imgur.com/dZZLT.png" rel="nofollow noreferrer">https://i.stack.imgur.com/dZZLT.png</a>
  So I want to connect a random number for each new Receipt.</p>