assignment29 - int x =-1 bool found = false do x...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/*Write a program that allows the user to enter foods and their calories. Allow for UP TO 100 entries, although the actual number may be way less. When the user types "done" then stop asking for new entries. Prompt the user for a food item; when entered, search the list and display the item and the number of calories. If the item is not found, indicate that. Stop prompting for items to search for when the user enters "done". Use the following screen shots as a guide. */ #include <iostream> #include <string> using namespace std; int main() { string foods[100]; int calories[100]; string searchTerm;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int x = -1; bool found = false; 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"); do { cout<<"Enter a product to look up:"<<endl; getline(cin, searchTerm); for(int i = 0; i < x; i++) { if (searchTerm == foods[i]) { cout << foods[i] << " has " << calories[i] << " calories." << endl; found = true; } } if( !found ) cout << searchTerm <<" was not found."<< endl; } while (searchTerm != "done"); }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online