Guys, stuck on a for loop issue Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

Guys, stuck on a for loop issue

Post by ChronoGraff »

Hi folks,

I am trying to basically show in a wxChoice UI element times starting with the current time + 1hr and then every 15 minutes for x times.

I'm experimenting with some code but just getting it wrong. I've gave it a good attempt but just can't seem to work this one out. I'm hoping to get a little help, again :(

My embarrassing attempt ins below. Again many thanks.

Code: Select all

    time_t now = time(0);
    size_t minutes = 60;

    int exp = 2;
    int hours = exp;
    int counter = 4;

    time_t start_time = (now + (60 * minutes));

    // std::cout << std::asctime(std::localtime(&start_time)) << std::endl;
    // start_time = now + (60 * minutes) * hours;
    // hours += hours;

    int time_ = 9;
    for (int i = 0; i < counter; ++i)
    {
        // std::cout << time_ << std::endl;
        // time_ += 2;

        std::cout << std::asctime(std::localtime(&start_time)) << std::endl;
        start_time += hours + 2;
    }
    
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

Re: Guys, stuck on a for loop issue

Post by ChronoGraff »

Hey folks solved, here is solution in case someone looking an example. Just have to format the time for the wxChoice

Code: Select all

   time_t t = time( 0 );
   int hours = 4;
   for ( int i = 0; i < 4; i++ )
   {
      cout << asctime( localtime( &t ) );
      t += hours * 3600;
   }
Post Reply