Software Design Using C++Review of Loop PatternsAnswering the QuestionRemember that we are trying to rewrite the test program so that the program now has the user interactively enter a list of items to buy. For each item to be purchased, the program should prompt the user to enter the unit price and the number of units of this item to buy. The program should output the cost for each type of item and, at the end, the total cost. Did you get something like the following for your main function? It is correct but has one annoyance that is explained below.
Although the above works, it is annoying to the user when the person goes to end the program. After the user enters a price of zero to end data entry, the program goes on to also ask for the next number of units. See if you can adjust the above loop pattern in just a small way so as to eliminate this undesirable feature. Then click on NEXT to see the answer. You can go back to the overall review listing: Review of Introductory Topics. Back to the main page for Software Design Using C++ |