I have a program code deal with a drug data in pharmacy ...the program is running without syntax error but I have a problem in search code ..it apply search on the first record only but didn't apply on other records..I have tomorrow an exam ..please help me..I'm sorry for my English because I'm Arabian .. this is the code

#include <fstream.h>
   void search_drug(char filename[20])
    {
      Pharmacy p;
      fstream f;
      int x;
      char ch;
      char Key[5];
    do{
     cout<<endl<<"Enter your choice"<<endl;
     cout<<"----->Press 1 for search with drug ID "<<endl;
     cout<<"----->Press 2 for search with drug name"<<endl;
     cout<<"----->Press 3 for search with drug amount"<<endl;
     cout<<"----->Press 4 for search with price"<<endl;
     cout<<"----->Press 5 for search with type of package"<<endl;
     cout<<"----->Press 6 for search with shelf number"<<endl;
     cin>>x;
      //int flag=0;
      f.open(filename,ios::in);
      
            while (!f.eof()){
       f.getline(p.drug_id,6,'|');
       f.getline(p.drug_name,19,'|');
       f.getline(p.drug_amount,5,'|');
       f.getline(p.price,7,'|');
       f.getline(p.type_of_package,11,'|');
       f.getline(p.shelf_num,3,'|');
switch(x){
case 1: 
       cout<<"Enter drug ID: ";
        cin>>Key;
	if(!strcmp(Key,p.drug_id)) {
	cout<<p.drug_id<<'|'<<p.drug_name<<'|'<<p.drug_amount
	<<'|'<<p.price<<'|'<<p.type_of_package<<'|'<<p.shelf_num<<endl;
	}
	else{
	cout<<endl<<"NOT FOUND ANY RECORD MATCHS WITH THE ID YOU ENTER"<<endl;
	}

		break;
case 2: 
       cout<<"Enter drug name: ";
        cin>>Key;
	if(!strcmp(Key,p.drug_name)) {
	cout<<p.drug_id<<'|'<<p.drug_name<<'|'<<p.drug_amount
	<<'|'<<p.price<<'|'<<p.type_of_package<<'|'<<p.shelf_num<<endl;
	}
	else{
	cout<<endl<<"NOT FOUND ANY RECORD MATCHS WITH THE NAME YOU ENTER"<<endl;
	}
		break;
case 3: 
       cout<<"Enter drug amount: ";
        cin>>Key;
	if(!strcmp(Key,p.drug_amount)) {
	cout<<p.drug_id<<'|'<<p.drug_name<<'|'<<p.drug_amount
	<<'|'<<p.price<<'|'<<p.type_of_package<<'|'<<p.shelf_num<<endl;
	}
	else{
	cout<<endl<<"NOT FOUND ANY RECORD MATCHS WITH THE AMOUNT YOU ENTER"<<endl;
	}
		break;
case 4: 
       cout<<"Enter drug price: ";
        cin>>Key;
	if(!strcmp(Key,p.price)) {
	cout<<p.drug_id<<'|'<<p.drug_name<<'|'<<p.drug_amount
	<<'|'<<p.price<<'|'<<p.type_of_package<<'|'<<p.shelf_num<<endl;
	}
	else{
	cout<<endl<<"NOT FOUND ANY RECORD MATCHS WITH THE PRICE YOU ENTER"<<endl;
	}
		break;
case 5: 
       cout<<"Enter type of package: ";
        cin>>Key;
	if(!strcmp(Key,p.type_of_package)) {
	cout<<p.drug_id<<'|'<<p.drug_name<<'|'<<p.drug_amount
	<<'|'<<p.price<<'|'<<p.type_of_package<<'|'<<p.shelf_num<<endl;
	}
	else{
	cout<<endl<<"NOT FOUND ANY RECORD MATCHS WITH THE TYPE YOU ENTER"<<endl;
	}
		break;
case 6: 
       cout<<"Enter shelf number: ";
        cin>>Key;
        if(!strcmp(Key,p.shelf_num)) {
	cout<<p.drug_id<<'|'<<p.drug_name<<'|'<<p.drug_amount
	<<'|'<<p.price<<'|'<<p.type_of_package<<'|'<<p.shelf_num<<endl;
	}
	else{
	cout<<endl<<"NOT FOUND ANY RECORD MATCHS WITH THE NUMBER YOU ENTER"<<endl;
	}
		break;



defult:"Please, Enter a correct choice";
}//end switch
}//end while


        f.close();
     cout<<endl<<"Do you want search again ?"<<endl
       <<"----->Press \"Y\" for Yes" <<endl<<"----->Press \"N\" for NO"<<endl ;
     cin>>ch;
       }  //do
         while (ch=='y' || ch=='Y');         






       }

im pretty inexperienced myself.... but,
there is no option to branch the code back from switch to test the next set of the drugs....
i wouldve prefered read() rather than takin details one by one.... much easier too...

what can I do regardless of the read function

this is a simple search code with the same problem

void search_drug(char filename[20])
    {
      Pharmacy p;
      fstream f;
      int x;
      char ch;
      char Key[20];
    do{
     cout<<endl<<"Enter your choice"<<endl;
     cout<<"----->Press 1 for search with drug ID "<<endl;
     cout<<"----->Press 2 for search with drug name"<<endl;
     cout<<"----->Press 3 for search with drug amount"<<endl;
     cout<<"----->Press 4 for search with price"<<endl;
     cout<<"----->Press 5 for search with type of package"<<endl;
     cout<<"----->Press 6 for search with shelf number"<<endl;
     cin>>x;
      int flag=0;
      f.open(filename,ios::in);
      
 
 

      
           if(x==1||x==2||x==3||x==4||x==5||x==6){
           	  if(x==1) {
              cout<<"Enter the drug ID that you search: ";
               }
              if(x==2) {
              cout<<"Enter the drug name that you search: ";
               }
               if(x==3) {
              cout<<"Enter the drug_amount that you search: ";
               }
		       if(x==4) {
              cout<<"Enter the price that you search: ";
               }
               if(x==5) {
              cout<<"Enter the type of package that you search: ";
               }
               if(x==6) {
              cout<<"Enter the shelf number that you search: ";
               }
	cin>>Key;
      read_drug(filename);
  
        if(!strcmp(Key,p.drug_id)||!strcmp(Key,p.drug_name)||!strcmp(Key,p.drug_amount)||!strcmp(Key,p.price)||!strcmp(Key,p.type_of_package)||!strcmp(Key,p.shelf_num)) {
       cout<<p.drug_id<<'|'<<p.drug_name<<'|'<<p.drug_amount<<'|'<<p.price<<'|'<<p.type_of_package<<'|'<<p.shelf_num<<endl;
          flag=1;
          }   //eng if
          
         if(flag==0)
          cout<<endl<<"NOT FOUND ANY RECORD MATCHS WITH THE KEY YOU ENTER"<<endl;
          } //end if(x==1|2|3|4|5|6)

            else {
             cout<<endl<<"Please, Enter a correct choice"<<endl;
            }
	  

         f.close();
     cout<<endl<<"Do you want search again ?"<<endl
       <<"----->Press \"Y\" for Yes" <<endl<<"----->Press \"N\" for NO"<<endl ;
     cin>>ch;
       }  //do
         while (ch=='y' || ch=='Y');         






       }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.