#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    11
    Rep Power
    0

    Question seems like program doesnt execute certain cin>> statements


    In my program I call a number of different functions and in between each I want pause and wait for user indicate they are ready to execute the next function. I do this by inserting cin>> statements between all my function calls. The problem is that after a while my cin>> stop working. That is, the program executes all the functions without pausing for user input.

    This is what my program looks like:

    void main()
    {
    SomeObj sobj;
    char c;

    //did not include code for A() B() or C() as they are very lenghty
    cin>>c; //works fine
    sobj.A();
    cin>>c;
    sobj.B(); //from here on problems.
    cin>>c;
    sobj.C();
    cin>>d;
    }

    I am guessing something in my functions A, B, or C is causing input to be sent? but then I dont understand why cin would start looking for input before AorBorC finished? Does anybody have an idea what may be happening, how to fix the problem, or what is a better way of doing what i'm trying to accomplish?

    Thanks!
  2. #2
  3. Bad Andy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    OH
    Posts
    275
    Rep Power
    11
    rather than doing a cin, you can use getch(). Its very handy. All you have to do is add #include<conio.h> at the top of your program, and type getch(); where you want the pause. If you want, you could even have an output before, telling the user to press any key.

    ps->

    void main()
    {
    SomeObj sobj;
    char c;

    //did not include code for A() B() or C() as they are very lenghty
    cin>>c; //works fine
    sobj.A();
    cin>>c;
    sobj.B(); //from here on problems.
    cin>>c;
    sobj.C();
    cin>>d;
    }


    cin >> d?? d is not declared anywhere.

IMN logo majestic logo threadwatch logo seochat tools logo