Function Return Time

so im a noob just messing around with C++ and im trying to make like a fack password hack to scare a friend but i only want it to run for 60 seconds and i cant figure out how to do it.

This is what i got

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
#include <iostream>
#include <conio.h>
#include <Windows.h>
using namespace std;

int main() 
{	
	Time = RunTime;
	cout << "Loading Password Hack..." << endl << endl;
	Sleep(4000);
	for(int Numbers = 1; RunTime <= 60; Numbers++) 
	{
		cout << Numbers;
	}
	getch();
	return 0;
}

int RunTime()
{
	for(int Time = 1; Time != 0; Time++)
	{
		Sleep(1000);
		return Time;
	}
}


please help thanks
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
#include <iostream>
#include <conio.h>
#include <Windows.h>
using namespace std;

int RunTime(int);

int main() 
{	
        int num = 1;
	cout << "Loading Password Hack..." << endl << endl;
	Sleep(4000);
	while(RunTime(num) < 60)
        {
               cout << num;
               num++;
        }
	getch();
	return 0;
}

int RunTime(int Time)
{
	Sleep(1000);
	return Time;
}


This should work.
Last edited on
Ok I tested it edited it a little and found out that what you did rendered the RunTime function I created inert

The new code
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
#include <iostream>
#include <conio.h>
#include <Windows.h>
using namespace std;

int RunTime(int);

int main() 
{	
    int num = 1;
	cout << "Loading Password Hack..." << endl << endl;
	Sleep(4000);
	while(RunTime(num) < 60000)
        {
               cout << num;
               num++;
        }
	cout << endl << endl << "Password Acquired" << endl;
	getch();
	return 0;
}

int RunTime(int Time)
{
	for(int Time = 1; Time != 0; Time++)
	{
		Sleep(1);
		return Time;
	}

}


Reason being in line 10 you do this
int num = 1
and then just have that as the condition on which the program spits out numbers. Therefore the RunTime function is not even doing any thing and not working....

But thanks for at least trying :)
Your code hasn't changed at all. It's still the same code and it has a redundant for loop. All your RunTime is doing is sleeping for a millisecond and then returning the number that was sent to it. I would suggest putting everything into main. It doesn't teach functions, but this code doesn't need any functions.

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

using namespace std;

int main() 
{	
        srand(int(time(0)));  //randomly generated numbers 
                              //have a time element to them
	cout << "Loading Password Hack..." << endl << endl;
	Sleep(4000);
	for(int x = 0; x < 600; x++)
        {
                 cout << rand() % 10;  //gives hacking feel
                 sleep(100);
        }//end for
	cout << endl << endl << "Password Acquired" << endl;
	getch();
	return 0;
}
Last edited on
Ok sorry for not responding in so long... your code works great id just like to now what
srand(int(time(0)))
does and what
cout << rand() % 10;
does just so i know how you did it for future reference thanks :)
srand(int(time(0))); sets the seed for rand(). rand() is a pseudo-random number generator. Without srand(), the numbers will always be the same from program to program, computer to computer. srand() just gives the random function different numbers based on the integer entered into it. Using the time function sends back the time as a double, so it needs to be typecasted as an int so it can be passed to srand(). The % sign is the C++ modulus operator. The modulus operator passes the remainder of the first number divided by the second number, so 7 % 5 = 2. The remainder of division will never be as big or bigger than the second number, so you have to use 10 as the second number to ensure that the result never has more than one digit.
Topic archived. No new replies allowed.