title: Input after cin.getline() fails?
body: <p>I am new to programming.  In my textbook, the problem presented it to write a program that asks a user for the rainfall for three months and calculates the average.</p>
  
  <p>I used the cin.getline() function to read the user input into an array.  The text states that there is no worry of the array being overflowed using the cin.getline() function.  However, if I enter a string larger than the array, my program goes haywire.  Why does this happen?</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  int main()
  {
   const int SIZE = 10;
   char month1[SIZE], month2[SIZE], month3[SIZE];
   double rain1, rain2, rain3, average;
  
   cout &lt;&lt; "Enter the name of the first month:  ";
   cin.getline(month1,SIZE);
   cout &lt;&lt; "Enter the rainfall for " &lt;&lt; month1 &lt;&lt; ":  ";
   cin  &gt;&gt; rain1;
   cin.ignore();
  
  
   cout &lt;&lt; "Enter the name of the second month:  ";
   cin.getline(month2,SIZE);
   cout &lt;&lt; "Enter the rainfall for " &lt;&lt; month2 &lt;&lt; ":  " ;
   cin  &gt;&gt; rain2;
   cin.ignore();
  
   cout &lt;&lt; "Enter the name of the third month:  ";
   cin.getline(month3,SIZE);
   cout &lt;&lt; "Enter the rainfall for " &lt;&lt; month3 &lt;&lt; ":  ";
   cin  &gt;&gt; rain3;
   cin.ignore();
  
   average = (rain1 + rain2 + rain3)/3;
  
   cout &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; setprecision(2) 
     &lt;&lt; "The average rainfall for " &lt;&lt; month1 &lt;&lt; ", " &lt;&lt; month2 
     &lt;&lt; ", and " &lt;&lt; month3 &lt;&lt; " is " &lt;&lt; average &lt;&lt; " inches\n\n";
  
  
   return 0;
  }
  </code></pre>