Accepting data for as long as the user wishes
<p>I am working on a project related to supermarket billing. I would like to know how to accept data from the user for as long as he. My current code is as below:</p>

<pre><code>#include &lt; stdio.h &gt; 
#include &lt; iostream.h &gt; 
#include &lt; conio.h &gt;

class product //start of class
{

    int itemno;
    char name[100];
    char itemtype[50];
    float price;
    float quantity;
    float total;

    public:

    void addprod();
    void calculate();
    void accept();
    void display();

}; //end of class

void product::addprod() //starting of addproduct()
{
    cout &lt;&lt; "enter the name of the poduct:";
    gets(name);

    cout &lt;&lt; "enter its type:";
    gets(itemtype);

    cout &lt;&lt; "enter its price:";
    cin &gt;&gt; price;

} //end of addproduct()

void product::accept() //starting of accept()
{
    cout &lt;&lt; "enter the item name:";
    gets(name);

    cout &lt;&lt; "enter the quantity:";
    cin &gt;&gt; quantity;

}

void product::calculate() {
    total = price * quantity;
}

void product::display() {
    cout &lt;&lt; "\nName";
    cout &lt;&lt; name;

    cout &lt;&lt; "\nPrice";
    cout &lt;&lt; price;
    cout &lt;&lt; "\nquantity";
    cout &lt;&lt; quantity;
    cout &lt;&lt; "\ntotal\n\n\n\n\n";
    cout &lt;&lt; total;

}

void main() {
    product s1[3];

    for (int i = 0; i &lt; 3; i++) {
        s1[i].addprod();
    }

    for (i = 0; i &lt; 3; i++) {
        s1[i].accept();

    }

    for (i = 0; i &lt; 3; i++) {
        s1[i].calculate();

    }

    for (i = 0; i &lt; 3; i++) {
        s1[i].display();

    }
}
</code></pre>

<p>My <code>main()</code> accepts everything 3 times but I want it to select everything for as long as the user wants. How can I achieve this?</p>

<p>Pls check this......</p>

<pre><code> #include&lt;stdio.h&gt;
 #include&lt;iostream.h&gt;
 #include&lt;conio.h&gt;
  int i;

 class product           //start of class
    {


            int itemno;
            char name[100];
            char itemtype[50];
            float price;
            float quantity;
            float total;


            public:

            void addprod() ;
            void calculate();
            void accept();
            void display()   ;




     }    ;                 //end of class




     void product::addprod()   //starting of addproduct()
        {
            cout&lt;&lt;"enter the name of the poduct:";
            gets(name)   ;

            cout&lt;&lt;"enter its type:";
            gets(itemtype);

            cout&lt;&lt;"enter its price:";
            cin&gt;&gt;price;

        }                                       //end of addproduct()



     void product::accept()           //starting of accept()
     {
            cout&lt;&lt;"enter the item name:";
            gets(name)  ;


            cout&lt;&lt;"enter the quantity:";
            cin&gt;&gt;quantity;

     }




     void    product::calculate()
        {
                    total=price*quantity;
         }



     void product::display()
        {
                cout&lt;&lt;"\nName";
                cout&lt;&lt;name;

                cout&lt;&lt;"\nPrice";
                cout&lt;&lt;price ;
                cout&lt;&lt;"\nquantity";
                 cout&lt;&lt;quantity;
                 cout&lt;&lt;"\ntotal\n\n\n\n\n";
                cout&lt;&lt;total;

        }





        void main()
        {
         int ch;
         product s1[3];



         cout&lt;&lt;"\n      1.      Add product";
         cout&lt;&lt;"\n     2.      Make Bill";
         cout&lt;&lt;"\n     3.      Display Bill";
         cout&lt;&lt;"\n     0.      Exit";
         cout&lt;&lt;"\n     Enter your choise(1,2,3,9)"     ;
         cin&gt;&gt;ch;


         switch(ch)
         {

         case 1:          cout&lt;&lt;"\n press 0 to exit";
                                 for(i=1;i!=0;i++)
                                s1[i].addprod();
                                break;
            }
</code></pre>

<p>}</p>
