Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   cin.get() / system("pause") (http://www.go4expert.com/forums/cinget-system-pause-t6019/)

johanjohan 24Aug2007 23:22

cin.get() / system("pause")
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.


Code: cpp

using namespace std;
int main()
    int counter;
    for(counter=1; counter < 101; counter++);
    cout << "is this working" <<endl;
return 0;

DaWei 24Aug2007 23:59

Re: cin.get() / system("pause")
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?

johanjohan 25Aug2007 00:44

Re: cin.get() / system("pause")
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

shabbir 25Aug2007 08:22

Re: cin.get() / system("pause")
You have a semicolon after the for loop which means the cout statement is not within the loop but outside the loop.

johanjohan 25Aug2007 08:39

Re: cin.get() / system("pause")
thank you

shabbir 25Aug2007 09:53

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

Originally Posted by johanjohan
thank you

My pleasure.

All times are GMT +5.5. The time now is 00:25.