Code is working perfectly, can't identify which test case is failing

#include
using namespace std;
int main() {
int n;
cin>>n;

for (int i=1;i<=n;i++)
{
    if (i==1 || i==n)
    {
        for (int j=0;j<n;j++)
        {
            cout<<"*"<<"\t";
        }
    cout<<endl;
    }

    else if (i!=1 && i<=(n/2))
    {
        for (int j=0;j<n/2;j++)
        {
            cout<<"*"<<"\t";
        }
        for (int j=0;j<(n/2)-1;j++)
        {
            cout<<"\t";
        }
        for (int j=0;j<n/2;j++)
        {
            cout<<"*"<<"\t";
        }
        cout<<endl;
    }

    else if (i==(n/2)+1)
    {
        cout<<"*";
        for (int j=0;j<n-1;j++)
        {
            cout<<"\t";
        }
        cout<<"*"<<endl;
    }
     else if (i!=n && i>(n/2)+1)
     {  for (int j=0;j<n/2;j++)
        {
            cout<<"*"<<"\t";
        }
        for (int j=0;j<(n/2)-1;j++)
        {
            cout<<"\t";
        }
        for (int j=0;j<n/2;j++)
        {
            cout<<"*"<<"\t";
        }
        cout<<endl;
     }
     else if (i==n)
     {
         for (int j=0;j<n;j++)
         {
             cout<<"*"<<"\t";
         }
     }

}

return 0;

}

This is the code. Provide guidance.

#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int space=1; // for the inner space
for (int i=1;i<=n;i++)
{
if (i==1 || i==n)
{
for (int j=0;j<n;j++)
{
cout<<"*"<<"\t";
}
}

else if (i<=(n/2))
{ 
    for (int j=0;j<=n/2-space;j++)
    {
        cout<<"*"<<"\t";
    }
    for (int j=0;j<2*space-1;j++)
    {
        cout<<" "<<"\t";
    }
    for (int j=0;j<=n/2-space;j++)
    {
        cout<<"*"<<"\t";
    }
    space+=1;
 }

else if (i>(n/2))
 {  
    for (int j=0;j<=n/2-space;j++)
    {
        cout<<"*"<<"\t";
    }
    for (int j=0;j<2*space-1;j++)
    {
        cout<<" "<<"\t";
    }
    for (int j=0;j<=n/2-space;j++)
    {
        cout<<"*"<<"\t";
    }
    space-=1;
 }

cout<<endl;
}

return 0;
}

I have corrected your code. Now, it’s working correctly.

Check the difference.

Hope this would help

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.