CIS Logo SVC Logo

   Computing & Information Systems
   Department

 

Schoology Facebook        Search CIS Site      Tutorials

Software Design Using C++



Review of Loop Patterns



Answering the Question


Remember 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.

You selected the sentinel-controlled loop plan, shown in outline below. This is correct since a unit price of zero functions as the sentinel, the special value used to signal the end of data entry.


cin >> Item;
while (Item != Sentinel)
   {
   Process(Item);
   cin >> Item;
   }

We will, of course, have to adapt this to somehow also include the input of the number of items to purchase. See if you can now rewrite the original program so that it follows the above pattern. Click on NEXT for further hints and answers on this.

You can go back to the overall review listing: Review of Introductory Topics.

Back to the main page for Software Design Using C++

Author: Br. David Carlson with contributions by Br. Isidore Minerd
Last updated: January 15, 2013
Disclaimer