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');
}