I really need a timer example, that I put into it seconds and after those seconds are up the application closes. Since I don't understand and know how to do that, I tried this:
1 2 3 4 5 6 7 8 9 10 11 12 13
std::cout << "Enter Y to restart. Closing automatically in 5 seconds..." << std::endl;
std::cin >> chrAns;
while (! (std::cin >> chrAns))
{
for (int intStart = 0; intStart < 5000; intStart++)
{
if (intStart == 5000)
{
exit(1);
}
}
}
Can someone tell me why that won't work? Or give me a timer example PLEASE AND THANK YOU!
that won't work because you don't have a time delay,
so when it executes the for loop, it will loop through it 5000 times in less than a second.
Because it's not waiting for a second to pass before incrementing. so your for loop would look something like the following:
1 2 3 4 5 6 7 8
for (int intStart = 0; intStart < 5000; intStart++)
{
if (intStart == 5000)
{
exit(1);
}
// insert time delay here like Sleep(1000);
}
the Sleep function is a time delay function where you pass in the number of milliseconds. It's included in windows.h. However you can only use that if you're using windows I think.