c++ - a beginners Q regarding multiple functions -


i need simple problem.. i'm trying learn c++ want game programming, have previous programming experience, not in c++.. question comes little this. i'm making dummy console application take numbers of current xyz , compare box of coords.. [x1,z1,y1 / x2,y2,z2] , check if you're within area.. can on own.. question is, how write allow reuse function have different output, eg if within x box x, if in y box y .. have..

    void withinrange(int x1, int y1, int z1, int x2, int y2, int z2) {      if (ccoordx > x1 && ccoordy > y1 && ccoordz > z1 && ccoordx < x2 && ccoordy < y2 && ccoordz < z2)     {      }  } 

i'm not sure how expand on make able reusable function..

you asked:

how write allow reuse function have different output, eg if within x box x, if in y box y

  1. write different functions check whether value in x box or y box.
  2. implement withinrange using other functions.
  3. use returned values of these functions make decisions in calling function(s).
bool withinxrange(int x1, int x2) {    return (ccoordx > x1  && ccoordx < x2); }  bool withinyrange(int y1, int y2) {    return (ccoordy > y1  && ccoordy < y2); }  bool withinzrange(int z1, int z2) {    return (ccoordz > z1  && ccoordz < z2); }  bool withinrange(int x1, int y1, int z1, int x2, int y2, int z2) {    return ( withinxrange(x1, x2) &&             withinyrange(y1, y2) &&             withinzrange(z1, z2) ); } 

in calling function:

int x1 = <some value>; int x2 = <some value>;  if ( withinxrange(x1, x2) ) {     // }