2280 Shares

C++ Help!, Help with my Program?

C++ Help!, Help with my Program? Topic: C# lower case string
July 18, 2019 / By Anstace
Question: Write a program that allows the user to enter foods and their calories into two arrays. 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. Next, prompt the user for a food item; when entered, sequentially search the list and display the item and the number of calories. If the item is not found, indicate that. Only exact matches need to work, so upper/lower case matters. Stop prompting for items to search for when the user enters "done". This is my program: #include #include using namespace std; int main() { string foods [100]; string product; double calories [100]; int counter = -1; bool done1 = false; bool done = false; do { counter++; cout << "Enter a menu item (enter 'done' when finished): "; getline(cin,foods [counter]); if (foods [counter] == "done"){ done1 = true; } else{ cout << "Enter the number of calories: "; cin >> calories [counter]; cin.ignore(); } } while (done1 == false); int i; int j; string tmp; //bubble sort for (i=0; i product) { upperbound = position - 1; } else { lowerbound = position + 1; } position = (lowerbound + upperbound) / 2; } if (foods[position] == product){ cout << foods[position] << " has " << calories[position] << " calories." << endl; cout << foods[1] << calories[1] << position; } if (lowerbound > upperbound) { cout << product << " was not found." << endl; }} } This is my output: Enter a menu item (enter 'done' when finished): Enter the number of calories: Enter a menu item (enter 'done' when finished): Enter the number of calories: Enter a menu item (enter 'done' when finished): Enter the number of calories: Enter a menu item (enter 'done' when finished): Enter the number of calories: Enter a menu item (enter 'done' when finished): quarter pounder with cheese large fries done cheeseburger Enter a product to look up: big mac has 540 calories. cheeseburger5400Enter a product to look up: CHEESEBURGER was not found. Enter a product to look up: cheeseburger has 540 calories. cheeseburger5401Enter a product to look up: apple was not found. Enter a product to look up: This is what the output should look like: Enter a menu item (enter 'done' when finished): Enter the number of calories: Enter a menu item (enter 'done' when finished): Enter the number of calories: Enter a menu item (enter 'done' when finished): Enter the number of calories: Enter a menu item (enter 'done' when finished): Enter the number of calories: Enter a menu item (enter 'done' when finished): *** DATA ENTRY FINISHED *** Enter a product to look up: big mac has 540 calories. Enter a product to look up: CHEESEBURGER was not found. Enter a product to look up: cheeseburger has 300 calories. Enter a product to look up: apple was not found. Enter a product to look up:
Best Answer

Best Answers: C++ Help!, Help with my Program?

Zaccai Zaccai | 4 days ago
These are the items which needed correction: calories array was unsorted bubble sort logic used to output items Check this out. http://pastebin.com/NdCrq6AK
👍 256 | 👎 4
Did you like the answer? C++ Help!, Help with my Program? Share with your friends

We found more questions related to the topic: C# lower case string


Zaccai Originally Answered: Help c++ Program I need help with this program Write a program that reads in a room number, its capacity, a?
You can put the input in a loop, and have the loop repeat if the user enters something invalid like a negative number. The code you gave actually doesn't even compile, so it's hard to debug it.
Zaccai Originally Answered: Help c++ Program I need help with this program Write a program that reads in a room number, its capacity, a?
You write it. Homework questions are in yet another classification. bypass there to get somebody silly and amoral sufficient to do your homework for you. next time attend type and take notes and study your textbook, you will not could come right here and look silly. this would be a intense communicate board for persons attempting to make certain genuine problems.

Sherlock Sherlock
Ok so your code compiled and is outputting stuff. If it's outputting the wrong numbers, check your calculations. Comment out different blocks of code at a time to narrow down where it's going wrong during compilation. put cout<<"*** DATA ENTRY FINISHED *** <
👍 110 | 👎 3

Sherlock Originally Answered: C++ program. I'm writing a program for a card game and I can't get the user input values to save.?
Post your code on past bin (http://pastebin.com), add this detail here to your question, and I will look into your code (maybe you could drop an e-mail through my profile - just as a reminder) ------------------ Hi Ron, did you realize that the code you posted is not complete?
Sherlock Originally Answered: C++ program. I'm writing a program for a card game and I can't get the user input values to save.?
#contain #contain void significant() { clrscr(); int a, b; cout<<"enter the sarting quantity >"; cin>>a; b=a+7; cout<<"n cout>>>"; for(int i=a; i<=b; i++) { cout<

If you have your own answer to the question c# lower case string, then you can write your own version, using the form below for an extended answer.