I am having trouble with an array. I have to enter some food items and their calorie values and then when finished I have to re enter the food item and then search the array to output their calorie values. My problem is how do I search an array. here is what I have so far

#include <iostream>
#include <string>

using namespace std;

int main()
{
	string food[100];
	string searchvalue;
	int calories[100];
	int x = -1;
	do
	{
		x++;
		cout <<"Enter a menu item (enter 'done' when finished): ";
		getline(cin, food[x]);
		if (food[x] != "done")
		{
		cout <<"Enter the number of calories: ";
		cin >> calories[x];
		cin.ignore();
		}
	}while(food[x] != "done");

	cout << '\n' << "*** DATA ENTRY FINISHED ***" << endl;

	do
	{
		for (
		cout << "Enter a product to look up: ";
		getline(cin, food[x]);
		if(food[x] != "done")
		{
		cout << food[x] << " has " << calories[x] << " calories." << endl;
		}
		}while(food[x] != "done");
}

I am having trouble with an array. I have to enter some food items and their calorie values and then when finished I have to re enter the food item and then search the array to output their calorie values. My problem is how do I search an array. here is what I have so far

#include <iostream>
#include <string>

using namespace std;

int main()
{
string food[100];
string searchvalue;
int calories[100];
int x = -1;
do
{
x++;
cout <<"Enter a menu item (enter 'done' when finished): ";
getline(cin, food[x]);
if (food[x] != "done")
{
cout <<"Enter the number of calories: ";
cin >> calories[x];
cin.ignore();
}
}while(food[x] != "done");

cout << '\n' << "*** DATA ENTRY FINISHED ***" << endl;

do
{
for (
cout << "Enter a product to look up: ";
getline(cin, food[x]);
if(food[x] != "done")
{
cout << food[x] << " has " << calories[x] << " calories." << endl;
}
}while(food[x] != "done");
}

look you are doing couple of mistakes before i tell you that you were suppose to post the code using code tags so do that ist
try to follow............
1) you are storing menu items in food[x]..and then again you are storing values of products in food[x]. dont do that!!!! declare variable like product with type string...
2) in search part try to compate product string with food[x] and use a increment counter to access values of food[x].e.g

if(product==food[j])

under loop

please post your code using code tags...

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.