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?