never ending program

So, In a couple of weeks is my brothers birthday, and we always pull a prank on each other on our birthdays. This year, I have something special in mind. I have an incredibly simple code here (below) that I want to send him, but I don't want him to be able to close it without my help (so like if he can't close it through conventional means, and it will close in response to a password) Any help would be greatly appreciated thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int ha(){
int num;
cin.get();
cout << "ha";
num++;
ha();
return num;
}

int main()
{
    cout << "Mwa";
    ha();
    return 0;
}
Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;
int num = 0;
int ha(){
    cin >> num;
    if(num==12345){
        cout << "Happy Birthday :)" << endl;
        return 0;
    }
    cout << "ha" << endl;
    ha();
    return num;
}

int main()
{
    cout << "Mwa" << endl;
    ha();
    return 0;
}


Hope this helps :)

AFAIK you can always kill a process from the task manager, so I don't think it's possible to make it block the pc.
Yeah, I agree with maeriden, if your brother is very small and he don't know how to kill a process, then only it will work.
Wouldn't that cause a stack overflow really easily?
closed account (Dy7SLyTq)
not with that program. he would have to leave it running for hours. and you can actually make it so you could only remove the program with a rescue disk. not recommending that (its malware status) just proving maeriden wrong
@maeriden & Himansh My brothers not all that smart with computers, especially since he just got windows8
My entire family have computers and none of them are smart, but when they run into programs that lock up their computer or just continually run without stopping they just turn off the computer and reboot it. Your prank is pointless as I'm sure your brother is smart enough to just reboot the computer.
he just close the program by click the "close" button, right? where are you running the program, anyway?
can you make a program that can call/open another c++.exe on close? because that could be fun if you say type "random numbers" to close, then 2 seconds later another opens with the same command. might slow him down on clicking the x.
closed account (Dy7SLyTq)
yep:
#include <cstdlib>

void afunc()
{
system(your.exe);
}

atexit(afunc);
Well yeah he could click the close button, but some libraries actually let you ignore the close button being pressed. So task manager to kill the process or a hard reset to shut off and reboot the computer. There is no way to lock the computer out like he wants for this alleged prank.
maybe you can make a program locks the mouse and some keys on the keyboard and only allow to press numbers to input the correct password for exitting

Edit: I dont know kow to do it.
Last edited on
BHXSpecter is right..like everyone knows how to take out the switch or hard reboot

@senhor but his bro could just turn pc off by button or switch
if he add the program to the startup folder the program will appear on the windows startup until input the right password and delete the program from startup folder
Yea..but the boy can just press the cross..but there is another way....hecan add like 500 of them to start up and than pull the prank..
Well you can figure how to keep it "open" which I'm sure would probably be classified as making a virus if it is impossible to close without using a special password or unplugging the machine/power off. But here is how I would do the infinite loop which probably isn't the best since it is a non-standard library but gets the job done.

1
2
3
4
5
6
7
8
9
10
11
#include <conio.h>
#include <iostream>

int main()
{
    while( true )
    {
        std::cout << "Ha" << std::flush;
        if( kbhit() && getch() == ']' ) return( 0 );
    }
}
closed account (Dy7SLyTq)
this would be so much easier in java...
If you can make a fullscreen program he cant press the cross cuz there is not a cross in fullscreen programs
Last edited on
closed account (Dy7SLyTq)
ill write you some java code later that will do what you want
Topic archived. No new replies allowed.