Displaying Time to the Nearest Tenth of a Second
Hi,
I'm trying to make this simple program that starts, and then when the user presses 1, it outputs the length of time since the program started. Basically I want it to give the time accurate to a tenth of a second, but I can only work out how to do it to the nearest second at present. Can anyone help so that it outputs something like: "Time from when the program was run: 4.3 seconds."?
Thanks.
Code:
#include <ctime>
#include <iostream>
#include <stdio.h>
#include <conio.h>
using namespace std;
int main()
{
int c;
time_t hold_time;
hold_time = time(NULL);
int time1 = hold_time;
int time2 = hold_time+10;
while (time1 < time2)
{
hold_time = time(NULL);
time1 = hold_time;
c=kbhit();
if (c != 0)
{
c = _getch();
if (c == '1')
cout << "Time from when the program was run: "
<< (time1-time2) << " seconds." << endl;
}
}
}