Left and Right

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Reaper

#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <Windows.h>
using namespace std;

void gotoxy(short x, short y)
{
	COORD pos = {x, y};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

int main()
{
	int count = 25;

	for(int i = 1 ; i < 26 ; i++)
	{
		gotoxy(i, 15);
		cout << "RIGHT";
		gotoxy(count, 20);
		cout << "LEFT";
		count--;
		Sleep(50);
	}
	gotoxy(30, 27);

	cout << endl << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();
	
	return 0;
}


When i run the program i get this:

RIGHTTTTTTTTTTTTTTTTTTTTTT
LLLLLLLLLLLLLLLLLLLLLLLEFT

the only problem is i need left to start at the right side of the screen and go left

and i need right to start at the left side of the screen and go right.

I need to go across the whole screen too, not just go to the center.

it should look like this:

RIGHTRIGHTRIGHTRIGHTRIGHTRIGHTRIGHTRIGHT... until it hits the right side of the screen

LEFTLEFTLEFTLEFTLEFTLEFTLEFTLEFTLEFTLEFT... until it hits the left side of the screen.

any suggestions.
@Reaper1

Is this any help?? Or are you needing to be able to read each word as it goes across, as LEFTLEFT, etc??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Left and Right.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <Windows.h>

using namespace std;

void gotoxy(short x, short y)
{
	COORD pos = {x, y};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

int main()
{
	int count = 75;

	for(int i = 0 ; i < 75 ; i++)
	{
		gotoxy(i, 10);
		cout << " RIGHT";
		gotoxy(count, 15);
		cout << "LEFT ";
		count--;
		Sleep(50);
	}
	gotoxy(30, 20);

	cout << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();
	
	return 0;
}
Last edited on
that is actually what i was looking for, i misread the question it was suppose to be like you wrote it, i see what you did, thank you for the help i appreciate it.
One more question if you dont mind.

This is my code for UP going from bottom to top and DOWN going from top to bottom.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "stdafx.h"
#include <string>
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <windows.h>
using namespace std;
 
void gotoxy(short x, short y) 
{
	COORD pos = {x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
 
int main ()
{
	int count = 25;
    
	for (int i = 0; i < 25; i++)
	{
		gotoxy(30, i);
        cout << "DOWN";
        gotoxy(40, count);
        cout << "UP";
        count--;
        Sleep(300);
    }
    gotoxy(30,27);
    
	cout << endl << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();

	return 0;
 
}


How can i make it so that it only displays the word up and down 1 time until the end and not not like 25 times. Like in my other program you got it to only display left and right 1 time until the end.
Like this. I enjoy these kind of problems.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Up and down.cpp : main project file.

#include "stdafx.h"
#include <string>
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <windows.h>
using namespace std;
 
void gotoxy(short x, short y) 
{
	COORD pos = {x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
 
int main ()
{
	int count = 24;
    
	for (int i = 0; i < 25; i++)
	{
		gotoxy(30, i);
        cout << "DOWN";
        gotoxy(40, count);
        cout << "UP";
        count--;
		Sleep(150);
		gotoxy(30, i);
		cout << "    ";
		gotoxy(40, count+1);
		cout << "  ";
        Sleep(150);
    }
    gotoxy(30,27);
    
	cout << endl << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();
	return 0;
 
}
Last edited on
Thats pretty cool, i like how i blinks. Keep up the good work. Thank you.
Will do, Reaper1, and your welcome. Mark this thread as solved, please. Much thanks.
@Reaper1

I changed up the program a bit. Now all 4 words are moving.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Up and down.cpp : main project file.

#include "stdafx.h"
#include <string>
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <windows.h>
using namespace std;

void gotoxy(short x, short y) 
{
	COORD pos = {x, y};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

int main ()
{
	int i;
	for ( i = 0; i < 75; i++)
	{
		gotoxy(i, 12);
		cout << " RIGHT";
		gotoxy(75-i, 14);
		cout << "LEFT ";

		gotoxy(40, 24-(i/3));
		cout << "UP";
		gotoxy(35, i/3);
		cout << "DOWN";

		Sleep(150);
		gotoxy(40, 24-(i/3)); // UP
		cout << "  ";

		gotoxy(35, i/3); // DOWN
		cout << "    ";
		Sleep(150);
	}
	gotoxy(40, 0);
	cout << "UP";
	gotoxy(35, 24);
	cout << "DOWN";

	gotoxy(30,13);    
	cout << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();
	return 0;
}
That is awsome, pretty sweet.
Topic archived. No new replies allowed.