I just want to take space as an empty place as I am coding an 8-piece puzzle problem. However ‘[space]’ is not being accepted.
Here’s the sample function.
void puzzle_8::initial_string_setup()
{
int i=0;
string initial="abcdefghi";
string allowed=" 12345678";
char to_check;
bool check=false;
while(i!=9)
{
cout<<"\n\n\t\t"<<initial[0]<<" | "<<initial[1]<<" | "<<initial[2]<<endl<<"\t\t---+-----+---"<<endl<<"\t\t"<<initial[3]<<" | "<<initial[4]<<" | "<<initial[5]<<endl<<"\t\t---+-----+---"<<endl<<"\t\t"<<initial[6]<<" | "<<initial[7]<<" | "<<initial[8]<<endl;
cout<<"Enter input for place "<<initial[i]<<": ";
cin>>to_check;
check=false;
for(int j=0;j<9;j++)
{
if (to_check==allowed[j])
{
check=true;
break;
}
}
if(check==true)
{
initial[i]=to_check;
i++;
}
else
{
cout<<"\n\nInvalid entry\n\n";
}
}
}
Also, how can I stop user from entering double digits?
EDIT:
Changing cin>>to_check
to to_check=getchar()
lets me take space
as an input and solves my query.