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