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

cin.get() / system("pause")

Discussion in 'C++' started by johanjohan, Aug 24, 2007.

  1. johanjohan

    johanjohan New Member

    Joined:
    Aug 19, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    I used code to create that littl box for the code to go into, but if it doesnt work then ill try again



    Ive used both cin.get() and system("pause") to let the program run while keeping the window open. In both cases the program runs one line and then stops. I dont understand why their stopping the program. Im using a dev compiler.

    thanks

    Code:
        
    #include<iostream>
    using namespace std;
    int main()
    {
        int counter;
        for(counter=1; counter < 101; counter++);
        cout << "is this working" <<endl;
    cin.get();
    return 0;
    } 
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    You're not clear. Runs one line? Which line? What do you mean, stops?

    Your for loop does nothing but count. That's an invisibly short delay. Is the cout working?
     
  3. johanjohan

    johanjohan New Member

    Joined:
    Aug 19, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    when I run the progra,, it prints "is this working" , just one time. below that it says please press any key to continue, when I hit the enter button the whole screen disapears.

    Its suppose to print out "is this working 100 times because the counter is set at 1. But it doesn't

    I checked the counter, cout, the loop and the whole program and cant find a flaw.

    Yet it doesnt work
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    You have a semicolon after the for loop which means the cout statement is not within the loop but outside the loop.
     
  5. johanjohan

    johanjohan New Member

    Joined:
    Aug 19, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    My pleasure.
     

Share This Page