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 &lt;&lt; &quot;Enter a menu item (enter 'done' when finished): &quot;; getline(cin, foods[x]); if (foods[x] != &quot;done&quot;) { cout &lt;&lt; &quot;Enter the number of calories: &quot;; cin &gt;&gt; calories[x]; cin.ignore(); } } while (foods[x] != &quot;done&quot;); do { cout&lt;&lt;&quot;Enter a product to look up:&quot;&lt;&lt;endl; getline(cin, searchTerm); for(int i = 0; i &lt; x; i++) { if (searchTerm == foods[i]) { cout &lt;&lt; foods[i] &lt;&lt; &quot; has &quot; &lt;&lt; calories[i] &lt;&lt; &quot; calories.&quot; &lt;&lt; endl; found = true; } } if( !found ) cout &lt;&lt; searchTerm &lt;&lt;&quot; was not found.&quot;&lt;&lt; endl; } while (searchTerm != &quot;done&quot;); }...
View Full Document

Ask a homework question - tutors are online