Manipulating the Console Screen (Confused)

closed account (3voN6Up4)
Hey guys, basically I have to write a program that makes the word "DOWN" appear at the top (near middle) and the word "UP" at the bottom (near middle) and when my program runs they are supposed to both at the same time move. "UP" is supposed to be on the upper part of the console and "DOWN" is supposed to be on the lower part of the console. It must move a line per second.

I'm probably halfway done, but could use some assistance. Just something to steer me into the right direction

Also, is there an alternative for system("cls") or any of the system functions? If you could provide an alternative or explanation, or even a forum regarding it, that would be awesome.

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <stdlib.h>
#include <windows.h>
using namespace std;
int main()
{
    cout << "\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
    Sleep(2); 
/*It was supposed to be 1, but I was experimenting to see
if I could see it slower with two, unfortunately it doesn't work :/*/
    system("cls");
    cout << "\n\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
    Sleep(2);
    system("cls");
    cout << "\n\n\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
    Sleep(2);
    system("cls");
    cout << "\n\n\n\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
    Sleep(2);
    system("cls");
    cout << "\n\n\n\n\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
    Sleep(2);
    system("cls");
    cout << "\n\n\n\n\n\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
    Sleep(2);
    system("cls");
    cout << "\n\n\n\n\n\n\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
    Sleep(2);
    system("cls");
    cout << "\n\n\n\n\n\n\n\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
    Sleep(2);
    system("cls");
    cout << "\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
    Sleep(2);
    system("cls");
    cout << "\n\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                      DOWN" << endl;
    cout << "\n\n\n\n\n\n\n\n\n" << endl;
    cout << "                                      UP" << endl;
}
Last edited on
A few suggestions.

1. a) Use functions rather than repetitive code.
b) Use either a loop or the built-in string functions to output a specific number of the same character.

2. The purpose of using a stream of newline characters '\n' is to get the previous content to scroll off of the visible console area, thus avoiding the need to clear the screen. If you tune the total number of lines output each time to be the same fixed number, the content should display in a predictable manner. Using functions makes this easier to achieve.

3. Don't use system() anything.

If you really must clear the screen (though it is may be unnecessary), see the article:
http://www.cplusplus.com/articles/4z18T05o/

For 1 (b) see (6) fill constructor http://www.cplusplus.com/reference/string/string/string/


Last edited on
Topic archived. No new replies allowed.