title: Trouble with while loop C++
body: <p>I'm relatively new to C++, but not to programming, and I'm confused as to why I am having this very strange issue with a while loop in my C++ program.</p>
  
  <pre><code>while (runUserInputLoop)
  {
      displayMenu();
      cout &lt;&lt; "Enter the number that corresponds with your choice from the menu: ";
      getline(cin, menuLoopChoice);
  
      if (menuLoopChoice == "1")
      {
          cout &lt;&lt; "Enter mean: ";
          cin &gt;&gt; mean;
          cout &lt;&lt; "Enter z-score: ";
          cin &gt;&gt; z;
          cout &lt;&lt; "Enter standard deviation: ";
          cin &gt;&gt; stDev;
          cout &lt;&lt; "Enter sample size: ";
          cin &gt;&gt; n;
          oneSampZInt(mean, z, stDev, n);
      }
  
      else if (menuLoopChoice == "2")
      {
          cout &lt;&lt; "Enter mean: ";
          cin &gt;&gt; mean;
          cout &lt;&lt; "Enter t-score: ";
          cin &gt;&gt; t;
          cout &lt;&lt; "Enter standard deviation: ";
          cin &gt;&gt; stDev;
          cout &lt;&lt; "Enter sample size: ";
          cin &gt;&gt; n;
          oneSampTInt(mean, t, stDev, n);
      }
  
      else if (menuLoopChoice == "3")
      {
          cout &lt;&lt; "Enter mean for first sample: ";
          cin &gt;&gt; mean1;
          cout &lt;&lt; "Enter mean for second sample: ";
          cin &gt;&gt; mean2;
          cout &lt;&lt; "Enter standard deviation for first sample: ";
          cin &gt;&gt; stDev1;
          cout &lt;&lt; "Enter standard deviation for second sample: ";
          cin &gt;&gt; stDev2;
          cout &lt;&lt; "Enter z-score: ";
          cin &gt;&gt; z;
          cout &lt;&lt; "Enter size of first sample: ";
          cin &gt;&gt; n1;
          cout &lt;&lt; "Enter size of second sample: ";
          cin &gt;&gt; n2;
          indepMeansZInt(mean1, mean2, stDev2, stDev1, n1, n2, z);
      }
  
      else if (menuLoopChoice == "4")
      {
          cout &lt;&lt; "Enter mean for first sample: ";
          cin &gt;&gt; mean1;
          cout &lt;&lt; "Enter mean for second sample: ";
          cin &gt;&gt; mean2;
          cout &lt;&lt; "Enter standard deviation for first sample: ";
          cin &gt;&gt; stDev1;
          cout &lt;&lt; "Enter standard deviation for second sample: ";
          cin &gt;&gt; stDev2;
          cout &lt;&lt; "Enter t-score: ";
          cin &gt;&gt; t;
          cout &lt;&lt; "Enter size of first sample: ";
          cin &gt;&gt; n1;
          cout &lt;&lt; "Enter size of second sample: ";
          cin &gt;&gt; n2;
          indepMeansTInt(mean1, mean2, stDev2, stDev1, n1, n2, t);
      }
  
      else if (menuLoopChoice == "5")
      {
          cout &lt;&lt; "Enter sample proportion: ";
          cin &gt;&gt; p;
          cout &lt;&lt; "Enter sample size: ";
          cin &gt;&gt; n;
          cout &lt;&lt; "Enter z-score";
          cin &gt;&gt; z;
          onePropZInt(p, n, z);
      }
  
      else if (menuLoopChoice == "6")
      {
          cout &lt;&lt; "Enter proportion from sample one: ";
          cin &gt;&gt; p1;
          cout &lt;&lt; "Enter proportion from sample two: ";
          cin &gt;&gt; p2;
          cout &lt;&lt; "Enter size of sample one: ";
          cin &gt;&gt; n1;
          cout &lt;&lt; "Enter size of sample two: ";
          cin &gt;&gt; n2;
          cout &lt;&lt; "Enter z-score";
          cin &gt;&gt; z;
          twoPropZInt(p1, p2, n1, n2, z);
      }
  
      else if (menuLoopChoice == "7")
      {
          cout &lt;&lt; "Enter chi-sqaured right value: ";
          cin &gt;&gt; chiSqrdRight;
          cout &lt;&lt; "Enter chi-sqaured left value: ";
          cin &gt;&gt; chiSqrdLeft;
          cout &lt;&lt; "Enter sample variance: ";
          cin &gt;&gt; variance;
          cout &lt;&lt; "Enter sample size: ";
          cin &gt;&gt; n;
          chiSqrdInt(chiSqrdRight, chiSqrdLeft, variance, n);
      }
  
      else if (menuLoopChoice == "8")
      {
          cout &lt;&lt; "Enter mean of differences: ";
          cin &gt;&gt; DBar;
          cout &lt;&lt; "Enter standard deviation of differences: ";
          cin &gt;&gt; SD;
          cout &lt;&lt; "Enter number of matched pairs: ";
          cin &gt;&gt; n;
          cout &lt;&lt; "Enter t-score: ";
          cin &gt;&gt; t;
          matchedPairsTInt(DBar, SD, n, t);
      }
  
      else if (menuLoopChoice == "A" || menuLoopChoice == "a")
      {
          cout &lt;&lt; "Enter population mean: ";
          cin &gt;&gt; mean1;
          cout &lt;&lt; "Enter sample mean: ";
          cin &gt;&gt; mean2;
          cout &lt;&lt; "Enter population standard deviation: ";
          cin &gt;&gt; stDev;
          cout &lt;&lt; "Enter size of sample: ";
          cin &gt;&gt; n;
          cout &lt;&lt; "Enter z-score: ";
          cin &gt;&gt; z;
          oneSampZTest(mean1, mean2, stDev, n, z);
      }
  
      else if (menuLoopChoice == "B" || menuLoopChoice == "b")
      {
          cout &lt;&lt; "Enter mean of sample one: ";
          cin &gt;&gt; mean1;
          cout &lt;&lt; "Enter mean of sample two: ";
          cin &gt;&gt; mean2;
          cout &lt;&lt; "Enter standard deviation of population one: ";
          cin &gt;&gt; stDev1;
          cout &lt;&lt; "Enter standard deviation of population two: ";
          cin &gt;&gt; stDev2;
          cout &lt;&lt; "Enter size of sample one: ";
          cin &gt;&gt; n1;
          cout &lt;&lt; "Enter size of sample two: ";
          cin &gt;&gt; n2;
          cout &lt;&lt; "Enter z-score: ";
          cin &gt;&gt; z;
          twoSampZTest(mean1, mean2, stDev1, stDev2, n1, n2, z);
      }
  
      else if (menuLoopChoice == "C" || menuLoopChoice == "c")
      {
          cout &lt;&lt; "Enter population mean: ";
          cin &gt;&gt; mean1;
          cout &lt;&lt; "Enter sample mean: ";
          cin &gt;&gt; mean2;
          cout &lt;&lt; "Enter sample standard deviation: ";
          cin &gt;&gt; stDev;
          cout &lt;&lt; "Enter size of sample: ";
          cin &gt;&gt; n;
          cout &lt;&lt; "Enter t-score: ";
          cin &gt;&gt; t;
          oneSamptTest(mean1, mean2, stDev, n, z);
      }
  
      else if (menuLoopChoice == "D" || menuLoopChoice == "d")
      {
          cout &lt;&lt; "Enter mean of sample one: ";
          cin &gt;&gt; mean1;
          cout &lt;&lt; "Enter mean of sample two: ";
          cin &gt;&gt; mean2;
          cout &lt;&lt; "Enter standard deviation of sample one: ";
          cin &gt;&gt; stDev1;
          cout &lt;&lt; "Enter standard deviation of sample two: ";
          cin &gt;&gt; stDev2;
          cout &lt;&lt; "Enter size of sample one: ";
          cin &gt;&gt; n1;
          cout &lt;&lt; "Enter size of sample two: ";
          cin &gt;&gt; n2;
          cout &lt;&lt; "Enter t-score: ";
          cin &gt;&gt; t;
          twoSamptTest(mean1, mean2, stDev1, stDev2, n1, n2, t);
      }
  
      else if (menuLoopChoice == "E" || menuLoopChoice == "e")
      {
          cout &lt;&lt; "Enter the population proportion: ";
          cin &gt;&gt; p1;
          cout &lt;&lt; "Enter the sample proportion: ";
          cin &gt;&gt; p2;
          cout &lt;&lt; "Enter the sample size: ";
          cin &gt;&gt; n;
          cout &lt;&lt; "Enter the z-score: ";
          cin &gt;&gt; z;
          onePropZTest(p1, p2, n, z);
      }
  
      else if (menuLoopChoice == "F" || menuLoopChoice == "f")
      {
          cout &lt;&lt; "Enter sample proportion one: ";
          cin &gt;&gt; p1;
          cout &lt;&lt; "Enter sample proportion two: ";
          cin &gt;&gt; p2;
          cout &lt;&lt; "Enter the x value of proportion one: ";
          cin &gt;&gt; x1;
          cout &lt;&lt; "Enter the x value of proportion two: ";
          cin &gt;&gt; x2;
          cout &lt;&lt; "Enter the size of sample one: ";
          cin &gt;&gt; n1;
          cout &lt;&lt; "Enter the size of sample two: ";
          cin &gt;&gt; n2;
          cout &lt;&lt; "Enter the z-score: ";
          cin &gt;&gt; z;
          twoPropZTest(p1, p2, x1, x2, n1, n2, z);
      }
  
      else if (menuLoopChoice == "q" || menuLoopChoice == "Q")
      {
          runUserInputLoop = false;
      }
  }
  </code></pre>
  
  <p>On the first iteration through the loop, everything works fine. However, on all subsequent iterations, the loop seems to iterate once, without any input, and then again, allowing me to enter input once again. So essentially, there is an extra iteration that causes it to perform this portion of the while loop twice:</p>
  
  <pre><code>displayMenu();
  cout &lt;&lt; "Enter the number that corresponds with your choice from the menu: ";
  getline(cin, menuLoopChoice);
  </code></pre>
  
  <p>Here is a picture of how it looks in the console: <a href="https://i.stack.imgur.com/7RCp8.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7RCp8.gif" alt="ghost iteration"></a>. The crudely circled portion is the "ghost iteration." I feel like it should be something simple, but I'm not extremely familiar with C++ yet, so I'm stumped. The full code for the program is available <a href="http://pastebin.com/WJ0MDcVW" rel="nofollow noreferrer">here</a> if necessary.</p>