Do While Loop menu in C++ : <p>I'm having trouble with this do-while loop menu for a program I'm working on for school. I've checked, and as far as I'm concerned I have written the code correctly. However, when testing, if I type 'y' or 'n' the result is the same: the menu streaming down 100's of times non stop until I exit the program. Any idea on what I'm doing wrong and how I can get it to display the menu properly every time? Thanks in advance. </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;string&gt;
#include "CashRegister.h"
#include "InventoryItem.h"
using namespace std;

int main()
{
// Variables
int selection, numUnits, cont;
double price;

// Use the first constructor for the first item
InventoryItem item1;
item1.setCost(5.0);
item1.setDescription("Adjustable Wrench");
item1.setUnits(10);

// Use the second constructor for the second item
InventoryItem item2("Screwdriver");
item2.setCost(3.0);
item2.setUnits(20);

// Use the third constructor for the remaining items
InventoryItem item3("Pliers", 7.0, 35);
InventoryItem item4("Ratchet", 10.0, 10);
InventoryItem item5("Socket Wrench", 15.0, 7);


do
{
    cout &lt;&lt; "#\t" &lt;&lt; "Item\t\t\t" &lt;&lt; "qty on Hand" &lt;&lt; endl;
    cout &lt;&lt; "------------------------------------------------------------------" &lt;&lt; endl;
    cout &lt;&lt; "1\t" &lt;&lt; item1.getDescription() &lt;&lt; "\t" &lt;&lt; setw(3) &lt;&lt; item1.getUnits() &lt;&lt; endl;
    cout &lt;&lt; "2\t" &lt;&lt; item2.getDescription() &lt;&lt; "\t\t" &lt;&lt; setw(3) &lt;&lt; item2.getUnits() &lt;&lt; endl;
    cout &lt;&lt; "3\t" &lt;&lt; item3.getDescription() &lt;&lt; "\t\t\t" &lt;&lt; setw(3) &lt;&lt; item3.getUnits() &lt;&lt; endl;
    cout &lt;&lt; "4\t" &lt;&lt; item4.getDescription() &lt;&lt; "\t\t\t" &lt;&lt; setw(3) &lt;&lt; item4.getUnits() &lt;&lt; endl;
    cout &lt;&lt; "5\t" &lt;&lt; item5.getDescription() &lt;&lt; "\t\t" &lt;&lt; setw(3) &lt;&lt; item5.getUnits() &lt;&lt; endl;
    cout &lt;&lt; "Which item above is being purchased? ";
    cin &gt;&gt; selection;

    // Validate the selection
    while (selection &lt; 1 || selection &gt; 5)
    {
        cout &lt;&lt; "Error, please make a valid item selection: ";
        cin &gt;&gt; selection;
    }

    cout &lt;&lt; "How many units? ";
    cin &gt;&gt; numUnits;

    // Validate the quantity of units to make sure it isn't a negative value
    while (numUnits &lt; 0)
    {
        cout &lt;&lt; "Error, please enter a valid quantity: ";
        cin &gt;&gt; numUnits;
    }

    // Use a switch statement to figure out which cost to pull
    switch (selection)
    {
    case 1: {price = item1.getCost();
        item1.changeUnits(numUnits); }
        break;
    case 2: {price = item2.getCost();
        item2.changeUnits(numUnits); }
        break;
    case 3: {price = item3.getCost();
        item3.changeUnits(numUnits); }
        break;
    case 4: {price = item4.getCost();
        item4.changeUnits(numUnits); }
        break;
    case 5: {price = item5.getCost();
        item5.changeUnits(numUnits); }
        break;
    }

    // Create a CashRegister object for this particular selection
    CashRegister transaction(price, numUnits);

    // Display the totals
    cout &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; setprecision(2);
    cout &lt;&lt; "Subtotal: $" &lt;&lt; transaction.getSubtotal() &lt;&lt; endl;
    cout &lt;&lt; "Sales Tax: $" &lt;&lt; transaction.getSalesTax() &lt;&lt; endl;
    cout &lt;&lt; "Total: $" &lt;&lt; transaction.getPurchaseTotal() &lt;&lt; endl;

    // Find out if the user wants to purchase another item
    cout &lt;&lt; "Do you want to purchase another item? Enter y/n: ";
    cin &gt;&gt; cont;

} while (cont != 'n' &amp;&amp; cont != 'N');

system("pause");
return 0;
</code></pre>

<p>}</p>
