Hi. I am having a problem with one of my class functions. It compiles fine and works "when it wants to". I am using the search_inventory function in my add_product function of the same class. sometimes it works perfectly fine however sometimes the search_inventory function causes an infinite loop when i call my add_product function. Since the problem does not occur every time I have no clue where the problem is. the StringUpper function converts a string to uppercase. Any help would be GREATLY appreciated. many thanks
void shopping_cart::search_inventory(vector<product> &list)
{string upper_prod, temp_name,search_prod;
product temp;
bool found=false;
unsigned int size=list.size();
cout<<endl<<"Enter product name: ";
getline(cin,search_prod);
do
{
upper_prod=StringUpper(search_prod);
cout<<"test";
if(upper_prod=="XXX")
{inventory_position=-1;
found=true;}
for(unsigned int i=0; i<size;i++)
{temp=list[i];
cout<<"test1";
temp_name=temp.get_product_name();
temp_name=StringUpper(temp_name);
if(temp_name==upper_prod)
{found=true;
inventory_position=i;}}
cout<<"test2";
if (found!=true)
{cout<<"\nProduct not found. \nPlease re-enter product name or enter xxx to return to main menu: ";
getline(cin,search_prod);}
}while(!found);
}
void shopping_cart::add_product(vector<product> &inventory1)
{product temp,prod1;
int counter=0,exist,amount, inventory_amount;
bool prod_exist=false, correct_amount=false;
search_inventory(inventory1);
...