I am making an inventory management system, its just starting of my program. I have a problem with this code.
When I start program and display objects its works correctly but after that when I again press 2 for display loop didn't break.
 #include<iostream>
 #include<fstream>
 using namespace std;
 class products
 {
char pname[20];
int pid;
int quantity;
int price;
public:
products()
{
    pname[0]='\0';
    pid=NULL;
    quantity=0;
    price=0;
}
void get()
{
    cout<<"Enter Product Name: ";
    cin>>pname;
    cout<<"Enter Product id: ";
    cin>>pid;
    cout<<"Enter Product Quantity: ";
    cin>>quantity;
    cout<<"Enter Product Price: ";
    cin>>price;
}
void display()
{
    cout<<"Product Name: ";
    cout<<pname;
    cout<<"\nProduct id: ";
    cout<<pid;
    cout<<"\nProduct Quantity: ";
    cout<<quantity;
    cout<<"\nProduct Price: ";
    cout<<price<<endl;
}
void sale()
{
    quantity--;
}
 };
 int _tmain(int argc, _TCHAR* argv[])
  {
products p;
int c;
fstream f;
f.open("product.dat",ios::binary|ios::in|ios::out|ios::app);
do{
    cout<<"Enter 1 to add product \n 2 to Display all products";
    cin>>c;
    switch(c)
    {
    case 1:
        p.get();
        f.write(reinterpret_cast<char*>(&p),sizeof(products));
        break;
    case 2:
        f.seekg(0,ios::beg);
        while(!f.eof())
        {
            f.read(reinterpret_cast<char*>(&p),sizeof(products));
            p.display();
        }
        break;
    }
}while(c!=0);
return 0;
}`
 
    