title: c++ using cin in a switch statement
body: <p>c++ I am writing a program with a menu. I am using a do while loop and a switch statement to execute the menu.  I am calling functions into the different cases.  When i call a function that has cin in it my program skips over the cin.  How can i get the cin to work in my switch statement? </p>
  
  <p>here is the function for my menu. after researching i tried different formats that aren't working.
  case 1, 2, and 5 are not working.       </p>
  
  <pre><code>    void Execute_Main_Menu(Student &amp;Temp, Student List[], int File_Size, ifstream &amp;fin)
      {
          char Choice ;
          ofstream fout ;
  
          do
          {
              cout &lt;&lt; "\n\nWhat would you like to do?  Enter 1-8: " ;
              cin &gt;&gt; Choice ;
              Student Temp ;
  
              switch(Choice)
              {
              case '1' : 
                  {
              File_Size=Read_Data(List, CAP) ;
              Another_Task() ;
              break ;
                  }
              case '2' : Open_Output_File(fout) ;
                  Print_List_To_File(List, File_Size, fout) ;
                  Another_Task() ;
                  break ;
              case '3' : Sort_Menu() ;
                  Execute_Sort_Menu(List, File_Size) ;
                  Another_Task() ;
                  break ;
              case '4' : Print_List(List, File_Size) ;
                  Another_Task() ;
                  break ;
              case '5' : Print_Student(Temp, List, File_Size) ;
                  break ;
              case '6' : cout &lt;&lt; "F" ;
                  break ;
              case '7' : cout &lt;&lt; "G" ;
                  break ;
              case '8' : cout &lt;&lt; "\n\nThank You.  Good Bye." ;
                  exit (0) ;
              default : cout &lt;&lt; "\nBad Input. Must be 1-8." ;
              }   
          }
              while(Choice != 8);
      }
  </code></pre>
  
  <p>here are examples of cin in functions i am calling</p>
  
  <pre><code>    bool Open_Output_File(ofstream &amp;fout) 
      {
          string Output ;
  
          cout &lt;&lt; "\nEnter the name of the output file: " ;
  
          getline(cin, Output) ;
          fout.open(Output.c_str()) ;
  
          if (fout.fail())
              return false ;
          else
              return true ;
      }   
      void Execute_Sort_Menu(Student List[], int File_Size)
      {
              char Choice ;
  
          do
          {
          cout &lt;&lt; "\nWhat would you like to do?  Enter 1 or 2: " ;
          cin &gt;&gt; Choice ;
  
              switch(Choice)
              {
              case '1' : Sort_B_Last_Name(List, File_Size) ;
                  Print_List(List, File_Size) ;
                  break ;
              case '2' : Sort_B_Average(List, File_Size ) ;
                  Print_List(List, File_Size) ;
                  break ;
              default : cout &lt;&lt; "\nYou have to enter the number 1 or the number 2." ;
              }
          }
          while(Choice !='1' &amp;&amp; Choice !='2');
      }   
      bool Open_Input_File(ifstream &amp;fin)
      {
          string Input ;
  
          cout &lt;&lt; "Enter the name of the input file: " ;
  
          getline(cin, Input) ;
          fin.open(Input.c_str()) ;
  
          if (fin.fail())
              return false ;
          else
              return true ;
      }
      int Read_Data(Student List[], int Size)
      {
          ifstream fin ;
          int     i = 0;
  
          if (Open_Input_File(fin)== true )
          {
              string Course_Name, Course_Id, Location ;
  
              getline(fin, Course_Name) ;
              getline(fin, Course_Id) ;
              getline(fin, Location) ;
              Read_Student(List[i], fin);
              while(!fin.eof())
              {
                  i++ ;
                  if(i == Size)
                  {
                      cout &lt;&lt; "\nArray is full.\n" ;
                      return (i);
                  } 
                  Read_Student(List[i], fin);
              }
          }
          else
          {
              cout &lt;&lt;"\nBad File Name. Did not open. Program terminated.\n\n";
              exit(0);
          }
          return (i);
          fin.close() ;
      }
  </code></pre>