title: C++ Planet Program Loop Skipping
body: <p>I'm writing a program that asks the user to enter their name, weight, and planet to find out what their weight would be on the given planet.  The program works fine, except it skips over the name input the second time.  I need some suggestions on how to fix this.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;iomanip&gt;
  #include&lt;string&gt;
  #include&lt;algorithm&gt;
  using namespace std;
  
  int main()
  {
  //declare variables and arrays
  string planets[8] = {"mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune"};
  double gravities[8] = {0.37, 0.78, 1.00, 0.38, 2.64, 1.16, 1.07, 1.21};
  double weight = 0.0;
  string planetChoice = " ";
  string name = " ";
  
  //give the user information and instructions
  cout &lt;&lt; "~~~~~~~~~~~~~~~~~~~~~Find your weight on different planets!~~~~~~~~~~~~~~~~~~~~~" &lt;&lt; endl;
  cout &lt;&lt; "This program calculates what your weight would be on various planets in " &lt;&lt; endl;
  cout &lt;&lt; "our solar system. To use this program, enter your full name, weight, and the " &lt;&lt; endl;
  cout &lt;&lt; "planet when prompted." &lt;&lt; endl;
  cout &lt;&lt; endl;
  cout &lt;&lt; "Choice of planets:" &lt;&lt; endl;
  cout &lt;&lt; "Mercury, Venus, Earth, Mars, Jupiter," &lt;&lt; endl;
  cout &lt;&lt; "Saturn, Uranus, and Neptune" &lt;&lt; endl;
  cout &lt;&lt; endl;
  
  
  cout &lt;&lt; "Full name (first and last) (\"exit\" to stop): ";
  getline (cin, name);
  
  while (name != "exit")
  {
      cout &lt;&lt; "Enter your weight: ";
      cin &gt;&gt; weight;
  
      cout &lt;&lt; "Choose your planet: ";
      cin &gt;&gt; planetChoice;
      transform(planetChoice.begin(), planetChoice.end(), planetChoice.begin(), tolower);
  
      for (int x = 0; x &lt; 8; x++)
      {
          if (planetChoice == planets[x])
          {
              weight = weight * gravities[x];
              switch(x)
              {
                  case 0:
                      cout &lt;&lt; name &lt;&lt; ", Your weight on the plannet closest to the sun (Mercury) would be: " &lt;&lt; weight &lt;&lt; "You'd be light as a feather!" &lt;&lt;endl;
                      break;
                  case 1:
                      cout &lt;&lt; name &lt;&lt; ", your weight on Venus would be: " &lt;&lt; weight &lt;&lt; "You'd be a bit lighter!" &lt;&lt; endl;
                      break;
                  case 2:
                      cout &lt;&lt; name &lt;&lt; ", your weight on your home planet (Earth) is: " &lt;&lt; weight &lt;&lt; endl;
                      break;
                  case 3:
                      cout &lt;&lt; name &lt;&lt; ", your weight on the red planet (Mars) would be: " &lt;&lt; weight &lt;&lt; endl;
                      break;
                  case 4:
                      cout &lt;&lt; name &lt;&lt; ", your weight on the largest planet (Jupiter) would be: " &lt;&lt; weight &lt;&lt; endl;
                      break;
                  case 5:
                      cout &lt;&lt; name &lt;&lt; ", your weight on the planet with rings (Saturn) would be: " &lt;&lt; weight &lt;&lt; endl;
                      break;
                  case 6:
                      cout &lt;&lt; name &lt;&lt; ", your weight on The Bull's Eye Planet (Uranus) would be: " &lt;&lt; weight &lt;&lt; "Your weight would be close to normal" &lt;&lt; endl;
                      break;
                  case 7:
                      cout &lt;&lt; name &lt;&lt; ", your weight on the ice cold planet of Neptune would be: " &lt;&lt; weight &lt;&lt; endl;
                      break;
                  default:
                      cout &lt;&lt; "Invalid planet name" &lt;&lt; endl;
                      break;
              }//end switch
          }//end if
      }//end for  
      cout &lt;&lt; "Full name (first and last) (\"exit\" to stop): ";
      getline (cin, name);
  }//end while
  
  system("pause");
  return 0;
  }//end of main function
  </code></pre>