Wrong values with division
<p>I'm having problems below. In my howmany function, it is supposed to read in how much money you have and the cost a item, then it's supposed to tell you how many of that item you can buy and the money leftover. So far all I can get it to display is a 0 for number of items allowed and money is displayed as the original amount entered.</p>

<p>Any help would be appreciated, also whenever I hit Q to quit the program I have to enter it 2 or 3 times for the loop to actually stop.</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

void bestbuy(double&amp;, double&amp;, double);
void discountresults (double&amp;, double&amp;);
void howmany(double&amp;, double&amp;);
char menu();

double price1, price2, price3;//bestbuy variables
double price, discount;//discountresults variables
double cash,item;//howmany variables

int main ()
{
  char choice;
  do
  {menu();
   choice = menu();}
   while(choice != 'Q');
   menu();

   system ("PAUSE");
   return 0;
}

void bestbuy(double &amp;val1,double &amp;val2, double val3)
{
     if (val1 &lt; val2 &amp;&amp; val1 &lt; val3)
      val2 = 1;
     else if (val2 &lt; val1 &amp;&amp; val2 &lt; val3)
      {val1 = val2;
       val2 = 2;}
     else
   {val1 = val3;
    val2 = 3;}
}

void discountresults(double &amp;price, double &amp;discount)
{
     double hold;
     hold = price;
     price *= discount; //discount amount
     hold -= price;
     discount = hold; //price after discount
}

void howmany(double &amp;money, double &amp;itemcost)
{
     double items;
     items = money / itemcost;
     itemcost = itemcost * items;
     money = money - itemcost;
}

char menu()
{
     char option;

     cout&lt;&lt;"(B)est Buy Calculation.\n";
     cout&lt;&lt;"(D)iscount Calculation.\n";
     cout&lt;&lt;"(H)ow Many Calculation.\n";
     cout&lt;&lt;"(Q)uit.\n";
     cout&lt;&lt;"Please enter the option B, D, H, or Q\n";
     cin&gt;&gt;option;

     switch(option)
{
case 'B':
 cout&lt;&lt;"Please enter 3 prices\n";
 cin&gt;&gt;price1;
 cin&gt;&gt;price2;
 cin&gt;&gt;price3;
 bestbuy(price1,price2,price3);
 cout&lt;&lt;"Your lowest price entered was "&lt;&lt;price1&lt;&lt;" and it was the "&lt;&lt;price2&lt;&lt;" number you entered.\n";
 break;
case 'D':
    cout&lt;&lt;"Please enter price of item and discount percent\n";
    cin&gt;&gt;price;
    cin&gt;&gt;discount;
    discountresults(price,discount);
    cout&lt;&lt;"Your discount amount is "&lt;&lt;price&lt;&lt;" and the discounted price is "&lt;&lt;discount&lt;&lt;endl;
    break;
case 'H':
    cout&lt;&lt;"Please enter amount of money available and cost of item\n";
    cin&gt;&gt;cash;
    cin&gt;&gt;item;
    howmany(cash,item);
    cout&lt;&lt;"You can buy "&lt;&lt;cash&lt;&lt;" of that item and have $"&lt;&lt;item&lt;&lt;" left over\n";
    break;
case 'Q':
    return option;


}}
</code></pre>
