I'm a novice programmer in C++ and I'm wondering how to update a value of an integer periodically. For example, increasing the value of an integer by 10 every 5 seconds. Thanks.
#include <iostream>
#include <ctime>
int main ()
{
// http://www.cplusplus.com/reference/ctime/
time_t start = time (NULL);
int val = 0;
while(true) // entire code must be inside
// this loop.
{
time_t update = time(NULL); // check time now
if (update - start > 10) // check if it was more
// than 10 seconds since
// last check
{
start = update;
std::cout << (val += 5);
}
}
}