I am writing a game in which I need to know whether or not a user preforms an action in one second or less. I can not use time() because it measures time in seconds. If the user starts the action half-way through a second it would mess with accuracy.
I am experimenting with clock(). I have got clock to work with some programs to make a delay, but not in this way to measure time:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
clock_t start = clock();
cout << "press enter...";
cin.ignore();
clock_t finish = clock();
double time = (finish-start)/CLOCKS_PER_SEC;
cout << "you took " << time << " seconds\n";
return 0;
}
This program returns 0 for time seemingly no matter how long I wait. I have tried several things including eliminating the need for the double time variable and testing the time variable to make sure it is exactly zero. Does anyone see what mistake I am making, or is there something I do not know about clock()?