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

  • Home
  • SEARCH
  • 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 890823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:47:41+00:00 2026-05-15T13:47:41+00:00

I’m writing a code to output fibonacci series in C++, which is simple enough,

  • 0

I’m writing a code to output fibonacci series in C++, which is simple enough, but since I’m new to programming, I’m considering ways to control

I was wondering if there’s a way to control time for when outputs come out without processing time being included (e.g. If it takes .0005 seconds to process my input and I want it to repeat the output in 1 second rather than 1.0005 seconds).

I also am wondering if there’s a way to just have it output (say 1) and then have it wait for me to press enter, which will make it output the second part (2).

Also, I’d appreciate any other suggestions on how to control output.

  • 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-05-15T13:47:41+00:00Added an answer on May 15, 2026 at 1:47 pm

    If you’re on Windows, a quick way to pause is to call system("pause"); This isn’t a very professional way of doing things, however.

    A way to pause with the std namespace would be something like this:

    cout << "Press Enter to continue . . ." << endl;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    

    As for your main question… If you’re just dealing with text output to the user, it’s not possible for them to notice a five microsecond delay. They can notice if your interval lengths fluctuate by tens of milliseconds, however. This is why sleep(..) functions sometimes fail.

    Let’s take your example of wanting to output another number in the Fibonacci sequence once per second. This will work just fine:

    #include <ctime>
    #include <limits>
    #include <iostream>
    
    void pause() {
        std::cout << "Press Enter to continue . . ." << std::endl;
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    }
    
    int main() {
        clock_t next = clock();
        int prev1, prev2, cur = 0;
    
        for (int i = 0; i < 47; ++i) {
            if (i < 2) cur = i;
            else cur = prev1 + prev2;
            prev2 = prev1;
            prev1 = cur;
    
            while (next > clock());
            std::cout << (i+1) << ": " << cur << std::endl;
            next += CLOCKS_PER_SEC;
        }
    
        pause();
        return 0;
    }
    

    The next number in the sequence is computed and ready to print prior to the wait, thus the computation time will not add any delay to the timed output.

    If you want your program to continue outputting at a fixed rate while your program works in the background, you’ll need to look into threads. You can have your results added to a queue in one thread, while another thread checks for results to print once per second.

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.