validation - c++ validate range of characters -
i'm writing function passed character first argument , integer second. need validate both simultaneously. specifically, character must between , j (including , j), , integer must between 1 , 10 (including 1 , 10).
the line wrote is:
if (toupper(row) < 'a' || toupper(row) > 'j' || col < 1 || col > 10) { return 0; } else { ... rest of function ... }
but not working correctly. in book read perform comparisons characters because integers themselves, can't figure out why ths won't work. point me in right direction?
edit address comments
0 number we're supposed return if input not valid.
this line of code part of project being graded "test driver" teacher wrote. test driver reporting function not returning correct result when input invalid (character not between or j, or number lower 1 or greater 10).
i structured code if statement above true, returns code supposed return, otherwise proceeds rest of function... can't figure out why test driver telling me i'm not returning code when given invalid input. other problem doesn't let see test driver sending our function, have no way of trouble shooting this.
i think shouldn't use toupper. why?
because maybe professor use invalid input like:
a, 5
and shouldn't allow lower cases pass test.
so in end if statement:
if ((row >= 'a' && row <= 'j') && (col > 0 && col < 11))
Comments
Post a Comment