Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   strange code (http://www.go4expert.com/forums/strange-code-t6084/)

johanjohan 28Aug2007 21:13

strange code
 
Ive written this code in different ways and it doesnt work right


if 100 is used in the prgram it works fine. It will count up or down to 100 or from 100 just fine. But when you put 1000 or 1000. For example : if i have the number 1000 in the program, it starts counting at 702 and not at 1.


Code:

#include<iostream>
using namespace std;

int main()
{
   
int number;
    for ( number = 1; number < 1001; number++)
    cout << number << "is this working" <<endl;

system("pause");
return 0;
}

its also been written like this (and doesnt work)
Code:

#include<iostream>

int main()
{
   
int number;
    for ( number = 1; number < 1001; number++)
    std::cout << number << "is this working" <<std::endl;

system("pause");
return 0;
}

its also been written like this (and doesnt work)
Code:

#include<iostream>
using namespace std;

int main()
{
   

    for ( int number = 1; number < 1001; number++)
    cout << number << "is this working" <<endl;

system("pause");
return 0;
}

it's been written many ways and each time it doesnt work, it always starts of at 702

The thing I dont understand is why does it pick the number 702 to start counting from?

again, with 100 it wont do this, it runs properly. With 1000 and 10000, ive tried using dopuble instead of in. no use.

thank you

DaWei 28Aug2007 21:34

Re: strange code
 
It works. Your output has merely overflowed the screen buffer because your screen buffer is not large enough. You can only scroll back to the beginning of the screen buffer, which, in your case, is where the 702 line is.

johanjohan 28Aug2007 21:59

Re: strange code
 
oh ok, thanks

is there a way I can fix that so that i can go back too 1 or is that a fundemntal thing?

if I write a program that goes to 10000 and it starts counting at 9702 to 10000, should I consider it working?

thank you

DaWei 28Aug2007 22:54

Re: strange code
 
You can increase the buffer size, but not indefinitely, of course. You could ask it to print every tenth line, or every 100th or 1000th, or whatever, by using the modulus operator. If you wanted to see them all, you could pause it after each line. I doubt you want to do that.

The other thing you can do is write the output to a file instead of the screen.

johanjohan 28Aug2007 23:31

Re: strange code
 
ok thanks


All times are GMT +5.5. The time now is 04:38.