Animated Computer

Hi, I'm new to C++, and am trying to write a program that creates an animated computer that displays random 1s and 0s on the screen.

I'm using \r to try and return to the next line, but it doesn't seem to work. Any ideas?

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <iostream>
#include <ctime>

using namespace std;

void main()
{
	
srand(time(0));

int counter=10;

while(counter>0)
{
	system("CLS");

	int a[3]={rand()%2,rand()%2,rand()%2};
	int b[3]={rand()%2,rand()%2,rand()%2};
	int c[3]={rand()%2,rand()%2,rand()%2};
	int d[3]={rand()%2,rand()%2,rand()%2};
	int e[3]={rand()%2,rand()%2,rand()%2};
	int f[3]={rand()%2,rand()%2,rand()%2};
	int g[3]={rand()%2,rand()%2,rand()%2,};
	int h[3]={rand()%2,rand()%2,rand()%2};
	int i[3]={rand()%2,rand()%2,rand()%2};
	int j[3]={rand()%2,rand()%2,rand()%2};

	cout<<"    ___________"<<endl;
	cout<<"   /          /|"<<endl;
	cout<<"  /__________/ |"<<endl;
	cout<<" |.---------.| |"<<endl;
	cout<<" ||         || |"<<endl;
	cout<<" ||         || |"<<endl;
	cout<<" ||         || |"<<endl;
	cout<<" |'---------'|/"<<endl;
	cout<<" `)__ _____(']"<<endl;
	cout<<"  [=== -- o ]/--._"<<endl;
	cout<<" __'---------'__  \\"<<endl;
	cout<<"[::::::::::: :::]  )"<<endl;
	cout<<"                   /T\\"<<endl;
	cout<<"                   \\_/";
	_sleep(100);
	
	cout<<"\r\r\r\r\r\r\r\r\r\r"<<" ||         || |"<<"\b\b\b\b\b\b\b\b\b\b\b\b\b";
	
	cout<<a[0];
	_sleep(50);
	

	cout<<b[0];
	_sleep(50);
	
	cout<<c[0];
	_sleep(50);
	
	cout<<d[0];
	_sleep(50);
	
	cout<<e[0];
	_sleep(50);
	
	cout<<f[0];
	_sleep(50);
	
	cout<<g[0];
	_sleep(50);
	
	cout<<h[0];
	_sleep(50);
	
	cout<<i[0];
	_sleep(50);
	
	cout<<j[0];
	_sleep(50);
	
	cout<<endl;
	_sleep(50);

	cout<<" ||         || |"<<"\b\b\b\b\b\b\b\b\b\b\b\b\b";

	cout<<a[1];
	_sleep(50);
	
	cout<<b[1];
	_sleep(50);
	
	cout<<c[1];
	_sleep(50);
	
	cout<<d[1];
	_sleep(50);
	
	cout<<e[1];
	_sleep(50);
	
	cout<<f[1];
	_sleep(50);
	
	cout<<g[1];
	_sleep(50);
	
	cout<<h[1];
	_sleep(50);
	
	cout<<i[1];
	_sleep(50);
	
	cout<<j[1];
	_sleep(50);
	
	cout<<endl;
	_sleep(50);

	cout<<" ||         || |"<<"\b\b\b\b\b\b\b\b\b\b\b\b\b";

	cout<<a[2];
	_sleep(50);
	
	cout<<b[2];
	_sleep(50);
	
	cout<<c[2];
	_sleep(50);
	
	cout<<d[2];
	_sleep(50);
	
	cout<<e[2];
	_sleep(50);
	
	cout<<f[2];
	_sleep(50);
	
	cout<<g[2];
	_sleep(50);
	
	cout<<h[2];
	_sleep(50);
	
	cout<<i[2];
	_sleep(50);
	
	cout<<j[2];
	_sleep(50);
	
	cout<<endl;
	_sleep(50);

	counter--;
	
}
}
You probably have to rewrite the code to draw the whole PC every time.

The responses at stack overflow suggest you have to use a library otherwise.

http://stackoverflow.com/questions/3277058/how-to-rollback-lines-from-cout
on Windows you can use 'windows.h' an the functions:
SetConsoleCursorPosition() to set the new position in the console;
GetConsoleScreenBufferInfo() to retrieve some info about Console screen buffer (current position of cursor, size, ecc.)
Thank you, the animation works now.
Topic archived. No new replies allowed.