ROOT Jupyter Notebook cin not working/getting skipped

Here’s a simple piece of C++ code:

int i,j,n;
n=8;
cout<<"Enter n:"<<endl;
cin>>n;
for(i=0;i<n;i++)
{
    for(j=(n-i);j>0;j--)
    {
        cout<<"*";
    }
    printf("\n");
}

The output that the above code gives is:

Enter n:
********
*******
******
*****
****
***
**
*

This is done on a C++ based ROOT Kernel on Jupyter Notebook. As you can see, the code does not throw any error at all, yet just takes n=8; and skips over the cin input line (if I remove n=8;, then the output is just “Enter n:”). I have tried to use scanf, getline and getch and all seem to have the same result in the end.

So, does anyone know why this might be happening?

Hello,

I’m afraid that is not supported in the C++ Jupyter notebook at the moment, and the cin >> n line does not ask for user input. This would probably need some Jupyter widget to be implemented and intercept the use of cin. The same that exists in a Python notebook for e.g. n = input().

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.