Question: C + + Use sentinel values to exit cycles. Assignment: Imagine you're a chef in a cooking show, and you're preparing ingredients for a recipe.

C++
Use sentinel values to exit cycles.
Assignment: Imagine you're a chef in a cooking show, and you're preparing ingredients for a recipe.
You need to keep track of the number of 'onions' you've prepared. Write a loop that reads strings from console input, representing different ingredients, e.g., 'onion', 'tomato', 'carrot', etc. The loop terminates when the string 'pepper' is read.
Be careful: ingredient names might have multiple words in them.
After the loop, your code should print out the total weight of the 'onions' prepared, where each 'onion' string read adds 50 grams to the total weight.
Sample run
Input
wheat flour
tomato
mozzarella
onion
tuna
olives
onion
pepper
Output
Total weight of onions: 100 grams
Note: Assume the string library has been already included. You need to only write the loop and declare any variable you need.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!