steve21
December 5th, 2008, 04:30 AM
Hey i have a program but it does not return the correct values for calories after the user inputs the product which is the food that has already been entered previously. I cant figure out how to make it search for the correct food, also im not sure how to make it says "product not found" if no previous input is found please help me>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string foods[100];
double calories[100];
string product;
int x = -1;
do
{
x++;
cout << "Enter a menu item (enter 'done' when finished):";
getline(cin, foods[x]);
if (foods[x] != "done")
{
cout << "Enter the number of calories: ";
cin >> calories[x];
cin.ignore();
}
} while (foods[x] != "done");
for (int y = 0; y < x; y++)
{
string temp;
cout<<"Enter a product to look up:"<<endl;
cin >>temp;
cin.ignore();
cout << temp << " has " << calories[y] << " calories"
<< endl;
}
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string foods[100];
double calories[100];
string product;
int x = -1;
do
{
x++;
cout << "Enter a menu item (enter 'done' when finished):";
getline(cin, foods[x]);
if (foods[x] != "done")
{
cout << "Enter the number of calories: ";
cin >> calories[x];
cin.ignore();
}
} while (foods[x] != "done");
for (int y = 0; y < x; y++)
{
string temp;
cout<<"Enter a product to look up:"<<endl;
cin >>temp;
cin.ignore();
cout << temp << " has " << calories[y] << " calories"
<< endl;
}
}