tags:

views:

425

answers:

6

Hello,

I'm having this weird problem. My code is simple:

#include <iostream>
using namespace std;

int main() {
    int num;
    cout << "number: ";
    cin >> num;

    for (int i=0;num>i;i++) {
        cout << i <<"\n";    
    }

system ("Pause");
return 0;    
}

If the input for example is 1000, the output contains numbers from 701-999. Any idea?

I'm using Dev-C++ IDE on Parallels.

+10  A: 

The loop ends when num>i is no longer true. This occurs when i is 1000, so the last loop executed will be with value 999. As for not seeing lower than 701, maybe your screen buffer is too small.

JoshD
Smells Windows: 300 lines is the cmd.exe's default max of vertical lines.
Dummy00001
+18  A: 

Actually it prints all of them, from 0 to 999, but your consoles buffer is not large enough. So you see only the last part. if you print into a file, not the console, you'll see :)

Armen Tsirunyan
+3  A: 

Did 0-700 scroll off the screen? Run your exe like this

your_program > out.txt

Then look at out.txt in an editor.

Lou Franco
+1  A: 

Regarding @JoshD answer, You will need to:

 for (int i=0;num>=i;i++) {
    cout << i <<"\n";    
}
aviv
+5  A: 

It will start with 0-999. Also, it appears to you that it starts with 701 because of your console screen settings. If you want to see it for yourself, change the newline into a space:

cout << i <<" "; 
Ruel
+2  A: 

Works absolutely fine for me. I'd suggest your IDE might be playing tricks on you. Could you redirect output into a file and check that?

Robin Welch