cin.getline function does'nt gets executed for the second time

akshatmaltare05's Avatar, Join Date: Aug 2011
Newbie Member
Code:
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
        int numnonterm;
        char terminal[10];
        char nonterminal[10][10];
        char tempterminal[10];
        cout<<"enter the terminals used";
        cin.getline (terminal,10);
        cout<<"enter the no of non terminal elements";
        cin>>numnonterm;
        cout<<"enter the nonterminals";
        cin.getline(tempterminal,10);
        
        if(int i=0)
        {
                return(0);
        }
}
the program exits without waiting for the user to enter the tempterm string .
have tried it several times but is not working
why?

Last edited by shabbir; 10Aug2011 at 21:35.. Reason: Code blocks
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Use fflush before the cin and that should work.