Why this code is not producing cout<<"enter" before input's

#include<bits/stdc++.h>
#include
#include
#include
#include
#include
typedef long long int ll;
#define mp make_pair
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int main() {
ios;
cout<<“enter”<<endl;
ll n,m;
cin>>m>>n;
ll maxx=max(n,m);
ll minn=min(n,m);
ll k=0;
cout<<maxx;
while(maxx > 1)
{
if(maxx%2==0)
{
if(maxx==2)
{
maxx=0;
++k;
++minn;
}
else
{
ll f=maxx-2;
maxx=2;
k+=(f/2);
minn+=(f/2);
}
}
else
{
ll f=maxx-1;
k+=(f/2);
minn+=(f/2);
}
ll a=maxx,b=minn;
maxx=max(a,b);
minn=min(a,b);
}
cout<<k;
}

Can you edit your post and reformat the code so that people can copy-n-paste and compile it? Use the “Preformatted text” button :slight_smile:

In the meantime, my guess as to what you were trying:

#include<bits/stdc++.h>
typedef long long int ll;
#define mp make_pair
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int main() {
    ios;
    cout<<"enter"<< '\n';
    ll n,m;
    cin>>m>>n;
    ll maxx=max(n,m);
    ll minn=min(n,m);
    ll k=0;
    cout<<maxx << endl;
    while(maxx > 1)
    {
        if(maxx%2==0)
        {
            if(maxx==2)
            {
                maxx=0;
                ++k;
                ++minn;
            }
            else
            {
                ll f=maxx-2;
                maxx=2;
                k+=(f/2);
                minn+=(f/2);
            }
        }
        else
        {
            ll f=maxx-1;
            k+=(f/2);
            minn+=(f/2);
        }
        ll a=maxx,b=minn;
        maxx=max(a,b);
        minn=min(a,b);
    }
    cout<<k;
}

“works” fine under gcc 7.4.0 (as in “enter” is displayed before it asks for input).

 cin.tie(0); cout.tie(0); 

would prevent this working if you didn’t manually flush cout, but that’s precisely what the “endl” does, so I’m not sure why this wouldn’t work.