never ending program

Jul 2, 2013 at 10:39am
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;
}
Jul 2, 2013 at 10:58am
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 :)

Jul 2, 2013 at 11:01am
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.
Jul 2, 2013 at 11:05am
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.
Jul 2, 2013 at 11:10am
Wouldn't that cause a stack overflow really easily?
Jul 2, 2013 at 2:00pm
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
Jul 2, 2013 at 3:45pm
@maeriden & Himansh My brothers not all that smart with computers, especially since he just got windows8
Jul 2, 2013 at 4:06pm
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.
Jul 2, 2013 at 4:09pm
he just close the program by click the "close" button, right? where are you running the program, anyway?
Jul 2, 2013 at 4:19pm
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.
Jul 2, 2013 at 4:33pm
closed account (Dy7SLyTq)
yep:
#include <cstdlib>

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

atexit(afunc);
Jul 2, 2013 at 4:40pm
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.
Jul 2, 2013 at 5:03pm
closed account (1v5E3TCk)
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 Jul 2, 2013 at 5:03pm
Jul 2, 2013 at 5:07pm
closed account (EwCjE3v7)
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
Jul 2, 2013 at 5:14pm
closed account (1v5E3TCk)
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
Jul 3, 2013 at 12:11am
closed account (EwCjE3v7)
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..
Jul 3, 2013 at 12:25am
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 );
    }
}
Jul 3, 2013 at 5:25am
closed account (Dy7SLyTq)
this would be so much easier in java...
Jul 3, 2013 at 11:09am
closed account (1v5E3TCk)
If you can make a fullscreen program he cant press the cross cuz there is not a cross in fullscreen programs
Last edited on Jul 3, 2013 at 3:16pm
Jul 3, 2013 at 2:52pm
closed account (Dy7SLyTq)
ill write you some java code later that will do what you want
Topic archived. No new replies allowed.