Hi guys, I'm working on a program that (for the step I'm having trouble w/ atm) is supposed to ask the user what movies they watched in each of the 12 months of the year and output the data to a file. After I enter the title of a movie though things start to go wrong. I'm sure there's more problems to my logic that I'll have to deal with after I get this problem solved (which, feel free to point them out) but I need help getting past this one for the time being. Here's my main method and the method relevant to my problem:

int main()
{
   int choice;
   do
   {
      cout << "1. Enter Movie Data" << endl
         << "2. Display Movie Data for a month" << endl
         << "3. Display Movie Data" << endl
         << "4. Quit" << endl << endl;

      cout << "Enter choice (1-4): ";
      cin >> choice;
      if(!(choice>=1 && choice<=4))
         cout << "That is not a valid option.\n";


      switch(choice)
      {
         case 1: 
         {   
            enterData();
         }
         break;

         case 2: 
         {   
            int m = 0;
            cout << "Enter month for which you want report: ";
            cin >> m;
            displayMonth(m);
         }
            break;

         case 3: 
         {
            displayAll();
         }      
         break;

         case 4: break;   
      }
   } while(choice!=4);
}

void enterData()
{
   int month = 0;
   ofstream output;
   output.open("movie.txt");
      do
      {
         char watched;
         month++;
         cout << "Have you watched any movie in month " << month << " [Y/N]: ";
         cin >> watched;
         switch(watched)
         {
            case 'y':
            case 'Y': 
            {
               while(watched == 'Y' or watched == 'y')
               {  
                  string name, date;
                  cout << "Enter Movie Name: ";
                  cin >> name;
                  cout << "Enter Date mm/dd//yy format: ";
                  cin >> date;
                  output << month << " " << date << " " << name << "\n";
                  cout << "Any more movies for month " << month << " [Y/N]:";
                  cin >> watched;
               }
            }
            break;             

            case 'n':
            case 'N': break;

            default: {"You did not enter Y or N.\n";}
               break;
         }
      } while (month < 13);

   output.close();   
}

And the program run...

1. Enter Movie Data
2. Display Movie Data for a Month
3. Display Movie Data
4. Quit

Enter choice (1-4): 1
Have you watched any movie in month 1 [Y/N]: Y
Enter Movie Name: The Iron Lady
Enter Date mm/dd/yy format: Any more movies for month 1 [Y/N]: Enter Date mm/dd/yy format: Any more movies for month 2 [Y/N]: Enter Date mm/dd/yy format: Any more movies for month 3 [Y/N]: Enter Date mm/dd/yy format: Any more movies for month 4 [Y/N]: Enter Movie Name: 

So yeah I don't see why it skips the cin for entering the date and outputs all those statements up to month 4 for some reason. Any help would be greatly appreciated! - Jamie

You can't use cin >> name and expect to get a string with spaces. call getline() instead so that it will capture spaces within the string

This article has been dead for over six months. Start a new discussion instead.