Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:04:01+00:00 2026-06-14T17:04:01+00:00

hello i am trying to get the output one time in while loop While(1){

  • 0

hello i am trying to get the output one time in while loop

While(1){
    if( current->tm_hour == 10 && current->tm_min == 0  ){
        Start_Function();
        std::cout <<  "Started" << std::endl;
    }

    if( current->tm_hour == 12 && current->tm_min == 0  ){
        End_Function();
        std::cout <<  "Ended" << std::endl;
    }

    Sleep(5000);
}

and i use sleep to refresh every 5 sec

so i want when the current Hour & minut = 10 & 00

it give me output Started and it call the function just one time and it contiune refreshing

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:04:02+00:00Added an answer on June 14, 2026 at 5:04 pm

    Edit: In light of @Joachim Pileborg’s comment

    It’s not the output that’s the problem, it’s that the functions are called (and the output printed) multiple times when it shouldn’t. – Joachim Pileborg

    Alternate solution

    int hasStarted = 0, hasEnded = 0;
    While(1){
    if( current->tm_hour == 10 && current->tm_min == 0 && !hasStarted  ){
    Start_Function();
        std::cout <<  "Started" << std::endl;
        hasStarted = 1;
    }
    
    if( current->tm_hour == 12 && current->tm_min == 0  && !hasEnded ){
    End_Function();
        std::cout <<  "Ended" << std::endl;
        hasEnded = 1;
    }
    
    Sleep(5000);
    }
    }
    

    The code above will force it to only do each of the operation’s once and continue refreshing…

    My original comment:

    In the command line/terminal as you’ve foundout the output is printed out continuously. Depending on what operating system you use (window/linux/mac) the solution will be easy or not so easy.

    I recommend looking up the gotoxy() function

    http://www.programmingsimplified.com/c/conio.h/gotoxy

    provided by the “conio.h” library for Windows or “ncurses.h” for Linux.

    “ncurses.h” doesn’t have the gotoxy() but it will provide you with a way to do the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello every One i am trying to get Ist date of All months in
I'm having one hell of a time trying to get my databinding to work
Hello I am trying to get the user profile picture and then merge into
I'm trying to get the hello world app running from the doc . I
Hello I am new at Haskell and i'm having problems trying to get this
I'm trying to get the maps api tutorial in the documentation ( http://developer.android.com/resources/tutorials/views/hello-mapview.html )
Hello I'm trying to learn ruby blocks. But I have a trouble to get
Hello I'm trying to archive an iOS app. I get this: warning: Application failed
The Quetion Hello. I'm trying to figure out the best way to use one
I'm trying to get a Hello World app working with groovy/log4j/ubuntu (working with Groovy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.