I have an issue with a function not working properly in my code --

It is a calendar creating program and when I call the function from the menu it blips the first line of text that it outputs to the user (asks a question for some input) and then immediately exits without error. I really am not sure what is doing this but below I have included the necessary code

void htmlOutput(int specialEventsCount, apvector<apstring> &EventsNames, apvector<int> &EventDateCount);


int main()
{

    int specialEventsCount;
    apvector<apstring> EventsNames;
    apvector<int> EventDateCount;
    
    EventsNames.resize(specialEventsCount);
    EventDateCount.resize(specialEventsCount);

.....

 case 4 : htmlOutput(specialEventsCount,EventsNames,EventDateCount); break;

}

void htmlOutput (int specialEventsCount, apvector<apstring> &EventsNames, apvector<int> &EventDateCount)
{

     int j, n,               //Counter for loop
         monthDaysDos;       //Month days set = to integer
     apstring firstDayName,  //First weekday of month
              monthDays;     //Asks user via apstring
     apvector<int> date;
     
     //
     apvector<apstring> EventsNames;
     EventsNames.resize(specialEventsCount);
     //
     
     date.resize(monthDaysDos);

     cout << "What day of the week is the first day of the month?" << endl;
     cout << "Please type in the full day name: ";
     getline(cin,firstDayName);

When I run this by itself if I put it in int main and add the variables that are referenced in there, it works perfectly.

Put a cin.ignore() before your getline() there's probably junk left in the istream.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.