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.
#include <iostream>
#include <conio.h>
#include <Windows.h>
usingnamespace 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....
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.
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.