Here is the piece of code I am having problems with. It is supposed to let me look up any items I put in the program previously. If the user did not enter a product earlier it should say "product not found".

My problem is that it remembers the first product I entered into the program, but any other entries I made after that aren't recognized and say "product not found".

Please help.

bool look = false;
		cout << "Enter a product to look up: ";
		getline (cin, search);
		for (int y = 0; y < x; y++)
			if (search == food[y])
				cout << food[y] << " has " << calories[y] << " calories." << endl;
				look = true;
			if ((look == false) && (search != "done"))
				cout << search << " was not found." << endl;
	while (search != "done");

I'm presuming that x is the number of array entries you filled. A more descriptive name would be more appropriate.

line 15 in your code would be executed for every pass of the loop.

If the first one doesn't match, then line 15 assumes you can't find it and terminates the loop.

You need to move the line 15 test outside the for loop and remove the break.

You will also need to set look to false before the for loop starts.

This question has already been answered. Start a new discussion instead.