Quit Function in c++


hi i wanted to make a quit function to this matrix effect... take it and use it to see wot i mean and the quit function can be used at any time in the matrix... , Thanks in advance




(Compile it to see wot i mean and by the way to close it press ctrl + alt + del and then close the task manager and right click the cmd and then click close)









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
#include<iostream>
#include<math.h>
#include<conio.h>
#include<string>
#include<windows.h>
#include<ctime>
using namespace std;
void full()
{
    keybd_event(VK_MENU,0x38,0,0);
    keybd_event(VK_RETURN,0x1c,0,0);
    keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0);
    keybd_event(VK_MENU,0x38,KEYEVENTF_KEYUP,0);
}
void randChar()    //randChar function
{
           char symbol = rand()%126+33;
           cout<<symbol<<"\b";}
           void randCharEnd()
           {
                     char symbol = rand()%126+33;
                     cout<<symbol;}
                     int spaceMaker(int a)
                     {
                          for(int i =0; i<=a; i++)
                          cout<<" ";}int timeWaster (int a)
                          {
                               a = a * 10;
                               for(int i=0; i<= a; i++)
                               cout<<" \b";
}



int main()
{
     full();
     system("COLOR 0A");
     srand((unsigned)time(NULL));
     int lineFeedCtr =0;
     int charCtr;    int clearCtr = 0;    char randChar2;    int ctr;    int spaceCtr = 0;            cout<<"M";    timeWaster(200);    cout<<"I";    timeWaster(200);    cout<<"N";    timeWaster(200);    cout<<"A";    timeWaster(200);    cout<<"'";    timeWaster(200);        cout<<"S ";    timeWaster(200);    cout<<"C";    timeWaster(200);    cout<<"R";    timeWaster(200);        cout<<"E";    timeWaster(200);    cout<<"A";    timeWaster(200);    cout<<"T";    timeWaster(200);    cout<<"I";    timeWaster(200);    cout<<"O";    timeWaster(200);    cout<<"N ";    timeWaster(300);        cout<<".";    timeWaster(200);    cout<<"..";    timeWaster(200);    cout<<"..";    timeWaster(200);  cout<<"."; timeWaster(200);

cout<<".";    timeWaster(300);    cout<<".";    timeWaster(300);     cout<<".";
timeWaster(300);    cout<<".\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";    timeWaster(1200);  randChar();  randChar();    randChar();    randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();    randChar();    randCharEnd();    timeWaster(200);        randChar();    randChar();    randChar();    randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();    randCharEnd();    timeWaster(175);        randChar();    randChar();    randChar();    randChar();  randChar(); randChar(); randChar();      randChar();       randChar();       randChar();       randChar();       randChar();       randChar();    randCharEnd(); randCharEnd();    timeWaster(150);        randChar();    randChar();    randChar();    randChar();    randCharEnd();      randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();       randChar();     timeWaster(125);        randChar();    randChar();    randChar();       randChar();       randChar();       randChar();       randChar();       randChar();    randChar();    randCharEnd();    timeWaster(120);          randChar();       randChar();       randChar();       randChar();       randChar();       randChar();     randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(110);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(100);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(90);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(80);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(70);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(60);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);        randChar();    randChar();    randChar();    randChar();    randCharEnd();    timeWaster(50);    randChar();    randChar();    randChar();    randChar(); randChar(); randChar();   randChar(); randChar(); randChar(); randChar(); randChar(); randChar(); randChar(); randChar(); randChar(); randChar(); randChar();  randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();randChar();  randCharEnd();    timeWaster(50);     while(1337>0)    {       ctr = 0;       charCtr = rand()%10+5;       spaceCtr = rand()%75;

if(clearCtr>=280)         {

clearCtr = 0;           }
while(ctr <= charCtr)

{

spaceMaker(spaceCtr);

ctr++;


randChar2 = static_cast<char>(rand()%126+33);


cout<<randChar2<<endl;

clearCtr++;
for(int b=0; b<=200;b++)
cout<<" \b";
}
 }
}

Under wich condition you want the program to quit?

btw. Nice program :)
LOL compile this program... and u'll see wot i mean once u start it.. :D
cuz i need a quit function for the matrix , its full screen , u cant type anything and u sure dont have a quit button! so i need something to make me quit the prog (while in the matrix) when i want!
Oh and thanks :)
If you add if (GetAsyncKeyState(VK_ESCAPE)) break;
somewhere in your first loop, you could stop the program by pressing "Escape"
Last edited on
Great PERFECT! i owe u ALOT MAN! thanks....
but i modifyed it!
before the for loop i did this
[code
if (GetAsyncKeyState(VK_ESCAPE))
{
exit(0);
}
[/code]
It Worked like a charm! thanks now compile it and have fun!
(dont forget the exit cuz without the matrix goes crazy :S
Avoid calling "exit". Here is what the standard says it does:

Calling the function
void exit(int);
declared in <cstdlib> (18.3) terminates the program without leaving the current block and hence without destroying any objects with automatic storage duration (12.4). If exit is called to end a program during the destruction of an object with static storage duration, the program has undefined behavior.


It might not matter in your case. But it does in the general case when manager objects aren't destroyed and hence leave OS resources locked. Just make it a habit to exit via return from main.
didnt get it really rephrase plz
so wot im suppose to use instead (confused)
Last edited on
Instead of using exit(0); use return 0;
Thanks
Topic archived. No new replies allowed.