This function of mine keeps on failing an autograder, I am trying to figure out if there is a problem with its logic flow? Any thoughts?
Basically, if the row is wrong, "invalid row" should be printed, and clearInput(); called, and return false. When y is wrong, "invalid column" printed, and clearInput(); called and return false.
When both are wrong, only "invalid row" is to be printed (and still clearInput and return false.
Obviously when row and y are correct, print no error and return true.
My function gets through most of the test cases, but fails towards the end, I'm a little lost as to why.
bool getCoords(int & x, int & y)
{
char row;
bool noError=true;
cin>>row>>y;
row=toupper(row);
if(row>='A' && row<='I' && isalpha(row) && y>=1 && y<=9)
{
x=row-'A';
y=y-1;
return true;
}
else if(!(row>='A' && row<='I'))
{
cout<<"Invalid row"<<endl;
noError=false;
clearInput();
return false;
}
else
{
if(noError)
{
cout<<"Invalid column"<<endl;
}
clearInput();
return false;
}
}