Line printing.

#include <iostream>

int main() {

	int x=0;
        int y=1000;
	
	while(x<1000) {
		x++, y--;
		system("clear");
		printf("\n%d\n%d", x,y);
		fflush(stdout);
		
	}
	
	return 0;
	
}

Without clearing the screen every time, how can i print 'x' and 'y' in the same spot?
How can i move the text-cursor back to the top of the screen every time through the loop?

You may use clrscr() function insist of system("clear") command.
the "conio.h" file support this function

Otherwise try the "gotoxy" command

gotoxy('x pos', 'y pos');

gotoxy(), clrscr(), and conio.h are borland turbo C things. This is a UNIX forum, not a DOS one.

If you're printing to a UNIX terminal it should support at least the basic ANSI escape sequences. I've written my own clrscr and gotoxy before which print escape sequences.

---------- Post updated at 09:15 AM ---------- Previous update was at 09:11 AM ----------

Incidentally: since you're using printf already, you should be #including stdio.h, and not iostream. You can use stdio, or iostream, but never both.

Your program will compile perfectly fine in pure C this way too, with no modifications to your program code itself, for you aren't using any C++ functions or syntax anyway.

---------- Post updated at 09:23 AM ---------- Previous update was at 09:15 AM ----------

Another common trick I've seen done to keep printing in the same place is to print a carriage return, not a newline. The cursor will move to the beginning of the line without moving down one line, allowing you to overwrite the same line again and again. You have to keep all your output on the same line this way, but it's dirt-simple.

int n;
for(n=1000; n>=0; n--)
{       // Print to stderr, stdout may not print without a newline due to buffering
        // We also use %4d instead of %d so it always overwrites 4 spaces.
        // Otherwise it might not overwrite ALL of what was printed last time.
        fprintf(stderr, "\rNumber is %4d", n);
        usleep(10000); // Wait 10 milliseconds
}

fprintf(stderr, "\n");