1

Is there was any way for the User to give a Real-Time input, while something is constantly being updated in the background. Basically, making the program not stop, when asking for user input.

For example, It will ask for user input, while a number is constantly being calculated.

1
  • 1
    Multithreading is the answer. Start 2 threads, one for the calculations and one for the user input. Commented Sep 29, 2013 at 5:35

1 Answer 1

-1

There are two ways of this problem, as I see it.

One is, as xebo commented, using multi threading. Use one thread for the constant calculation of the number or whatever, and another thread to look for user input constantly.

The second method is a simpler on and works only if you are using cin( from the std namespace) to get user input. You can nest another while loop inside the calculation loop like this:

#include <iostream>
using namespace std;

int main()
{
    int YourNumber;
    char input;         //the object you wish to store the input value in.
    while(condition)    //Whatever your condition is
    {
        while(cin>>input)
        //This while says that the statement after (cin»input)
        //is to be repealed as long as the input operation 
        //cin>>input succeeds, and
        //cin»input will succeed as long as there are characters to read 
        //on the standard input.
        {
             //Update process your input here.
        }
        //D what the normal calculations you would perform with your number.
    }
return 0;
}

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.