Sunday, 12 February 2012

Classical Programming - 1 : validation (c++)

int validMonth(int mon, char* errmes){
  int res = 0;
  if(mon > 0 && mon <=12){
    res  = 1;
  }
  else{
    strcpy(errmes, "Invalid month (1<=month<=12)");
  }
  return res;
}
write the above function in one line:
int validMonth(int mon, char* errmes){
return (mon>0&&mon<=12)||(strcpy(errmes, "Invalid month (1<=month<=12)")&& 0);
}

No comments:

Post a Comment