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 8326447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:45:52+00:00 2026-06-09T00:45:52+00:00

I am making a Quiz program. So what I want is whenever any question

  • 0

I am making a Quiz program. So what I want is whenever any question in presented before the user, then he has 30 seconds to answer it. And in these 30 seconds I want the beep sound (‘\a’) at an interval of 1 second. Now I want is that this beep sound should stop as soon as the user enters any input. I have created this small function to produce the beep sound for 30 sec void beep(){ for(int i=0;i<30;i++){cout<<"\a"; Sleep(1000); }
}

But I don’t know how to stop it as soon as the user enters his/her answer because once I call it nothing can be done until its over.
Can anyone give any workaround for it?

  • 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-09T00:45:53+00:00Added an answer on June 9, 2026 at 12:45 am

    Disclaimer: I’m not a Windows programmer, I don’t know if this is good style or even if it will compile or work. I can’t test it here. However, as no one else has given a solution, it’s a starting point. I’ll edit this answer as I learn more, and hopefully someone who knows more about this will turn up.

    Edit: I faked out _kbhit() to a trivial function returning false, and it at least compiles and looks like it runs ok

    Edit: Ok I do have ms visual studio at work, I just never use it. The code as it is right now compiles and works (I suspect the timing is off though).

    Edit: Updated it to immediately read back the key that was hit (rather than waiting for the user to hit enter).

    This is the important function: http://msdn.microsoft.com/en-us/library/58w7c94c%28v=vs.80%29.aspx

    #include <windows.h>
    #include <conio.h>
    #include <ctime>
    #include <iostream>
    #include <string>
    
    int main()
    {
        time_t startTime, lastBeep, curTime;
        time(&startTime);
        lastBeep = curTime = startTime;
        char input = '\0';
    
        while ( difftime(curTime,startTime) < 30.0 )
        {
            if ( _kbhit() ) // If there is input, get it and stop.
            {
                input = _getch();
                break;
            }
            time(&curTime);
            if ( difftime(curTime,lastBeep) > 1.0 ) // More than a second since last beep?
            {
                std::cout << "\a" << "second\n" << std::flush;
                lastBeep = curTime; // Set last beep to now.
            }
        }
        if ( input )
        {
            std::cout << "You hit: \"" << input << "\"\n" << std::flush;
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a quiz application with question and answer. I want to make
I am making a quiz app for Android. The user has 30 seconds to
I'm making a simple quiz database, where a question has an answer and one
I'm making a quiz in Actionscript 2.0. The quiz has 8 questions. Each question
I am making a basic quiz program, that when finished will allow the user
I'm making a quiz for Android and I want a limited time to answer
I am making a quiz app for chemistry reactions. The app gives the user
Hey guys, I'm making a quiz with a limit, I want to keep track
Making a simple three question PHP quiz. Each question is displayed on a page
Here's the quiz question: Adding two strings or making multiple copies of the same

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.