So I have the below code to check the input, I'm just having trouble because apparently flushing the input causes the tests (its an assignment) to lock up and I need to manually break out of it.
The problem is that if I remove the flushing of the input it it doesn't error out correctly.
i.e. instead of enterin rrrtrtere and it errors out once, it will error out 9 times.
This is the test data:
Test 3:
r4789kfdour49frkbjfds-r4tnjfdw0-ir4kljfdrwep943rpiofdkljfd04wpgenbp['er-=iohfgf$
ioufkljfdfdskljfpiofdsnmvfpkorekl,mfrksdveiouwefds piode
h2
v3
h-1
q
This is the whole function below. So if the person presses 'i' it goes to another function, if they press 'q' it quits the whole thing, if they press 'h0','h1',v0','v1' or 'v2' it runs another function. Anything else entered should circle back to requesting input again, this is where I'm having the problem.
void get_input(int puzzle[][COLS])
{
char dir='\0';
int col=COLS-1;
int row=ROWS-1;
int rowcol=-1;
bool flag = false;
while(!flag)
{
cout<<"Please enter next move : ";
cin>>dir;
if( dir== 'i')
{
print_instructions();
continue;
}
else if( dir=='q')
{
break;
}
else
{
char p;
cin>>p;
const char * temp;
temp= &p;
rowcol= atoi(temp);
if((dir=='h' && row<=1 && rowcol<=ROWS)
|| (dir=='v' && col<=2 && rowcol<=COLS))
{
movePuzzle(puzzle, dir, rowcol);
print_puzzle(puzzle);
flag = is_winning_state(puzzle);
}
else
{
cin.ignore(1000,'\n');
continue;
}
if(flag)
{
cout<<"CONGRATULATIONS - You have solved the puzzle"<<endl;
}
}
}
}