Ok, here is the loop from my code, a for loop inside a do...while. The title is a tad misleading, I couldn't edit it though. Probably not the most efficient coding to do what I want but I have no errors and it is so close to working. When I recall an item that was previously entered into an array, the loop correctly finds the result and prints the correct message, but also prints the error message later on. It doesn't seem that the tmp variable should have been changed yet to mess with it, plus it fails when using "done" as well. The error message always is displayed.

do
	{
		string tmp = "";
		cout << "Enter a product to look up: "; getline (cin, target);
		for (int i = 0; i < x; i++)
		{
			if (food[i] == target)
			{
				tmp = target;
				cout << target << " has " << cal[i] << "calories." << endl;
			}
			else 
			{
			}
		}
		if ((tmp != target) || (target != "done"))
		{
			cout << target << " was not found." << endl;
		}
		else
		{
		}
	} while (target != "done");

Maybe I should be using an else if for the second part of line 16. I am going to try that out.

Correction: I had to change line 16 to equal instead of not equal then move line 18 into the else statement and it all works great.

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.