I'm trying to produce an output of 3 loops counting by five from 0 to 30, each number representing the number of seconds since the beginning of the loop. (i.e. 10 = 10 seconds since loop started).
However, my code is looping each number as well, so I end up with multiple (in the ballpark of hundreds) lines of each number.
#include
#include
#include
#include
#include
However, my code is looping each number as well, so I end up with multiple (in the ballpark of hundreds) lines of each number.
#include
#include
#include
#include
#include
[Error: Irreparable invalid markup ('<sys/time.h>') in entry. Owner must fix manually. Raw contents below.]
I'm trying to produce an output of 3 loops counting by five from 0 to 30, each number representing the number of seconds since the beginning of the loop. (i.e. 10 = 10 seconds since loop started).
However, my code is looping each number as well, so I end up with multiple (in the ballpark of hundreds) lines of each number.
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cmath>
#include <sys/time.h>
using namespace std;
void current_time() {
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
cout << asctime(timeinfo) << endl;
}
int main() {
timeval my_timeval;
double t1, t2, my_elapsed_secs = 0;
gettimeofday(&my_timeval, NULL);
int x = 0;
while (x < 3) {
t1 = (my_timeval.tv_sec);// * 1000000) + my_timeval.tv_usec;
while (my_elapsed_secs < 30) {
gettimeofday(&my_timeval, NULL);
t2=(my_timeval.tv_sec);// * 1000000) + my_timeval.tv_usec;
my_elapsed_secs = (t2 - t1);// / 1000000;
if (fmod(my_elapsed_secs, 5) == 0)
cout << my_elapsed_secs << endl;
}
x++;
}
}
any ideas on how to fix it?
However, my code is looping each number as well, so I end up with multiple (in the ballpark of hundreds) lines of each number.
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cmath>
#include <sys/time.h>
using namespace std;
void current_time() {
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
cout << asctime(timeinfo) << endl;
}
int main() {
timeval my_timeval;
double t1, t2, my_elapsed_secs = 0;
gettimeofday(&my_timeval, NULL);
int x = 0;
while (x < 3) {
t1 = (my_timeval.tv_sec);// * 1000000) + my_timeval.tv_usec;
while (my_elapsed_secs < 30) {
gettimeofday(&my_timeval, NULL);
t2=(my_timeval.tv_sec);// * 1000000) + my_timeval.tv_usec;
my_elapsed_secs = (t2 - t1);// / 1000000;
if (fmod(my_elapsed_secs, 5) == 0)
cout << my_elapsed_secs << endl;
}
x++;
}
}
any ideas on how to fix it?
