1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'C++' started by akshatmaltare05, Aug 10, 2011.

  1. akshatmaltare05

    akshatmaltare05 New Member

    Joined:
    Aug 10, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Aug 10, 2011
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Use fflush before the cin and that should work.
     

Share This Page