Question: c++ You must use a do while loop in the following program: Write, compile, debug, and run a program that will use the specified loops
c++
You must use a do while loop in the following program: Write, compile, debug, and run a program that will use the specified loops to do the following: This program will ask the user for items to buy and their quantities, and write a shopping list to a file.
Open a file named shopping.txt for write access
Use a do while loop to get the items from the user:
Prompt the user for an itemto place on the shopping list (i.e. apples).
Prompt for the quantity of that item, using the name of the item in the prompt For example, if the user entered apples, prompt How many apples? (dont worry about grammar and plurals.)
Write each item and its quantity to the file, item first, quantity second (i.e. apples 5) with only spaces between each write, nothing else (no punctuation, no endl, no ) Ask the user if they want to keep entering items Loop until the user enters N or n to this question (loop should only end if they enter N or n.) (This is the do while loop condition.)
Close the file
Open the same file for read access Use a while loop to: Read each item and quantity from the file, i ndividually, into separate variables
Display the shopping list to the screen, with each quantity and item on a new line (after a heading line)
Read individual item and quantity values from the file using the >> operator. Do not read by line. Do not use any other method to read from the file (i.e. dont use getline, rdbuf, or any other way)
The while loop should read until it reaches the end of the file. (it should not loop a certain number of times dont count how many writes the earlier loop did and then do the same number of reads.)
Close the file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
