I need to know is there a better / shorter way to write following code in c++. (while going through the main if-else (step by step), additional check for variable 'y' will be added)
int x = 5, y = 4;
if(x == 1){
if(y == 1)
printf("ok");
else
printf("not ok");
}
else if(x == 2){
if((y == 1) || (y == 2))
printf("ok");
else
printf("not ok");
}
else{
if((y == 1) || (y == 2) || (y == 3))
printf("ok");
else
printf("not ok");
}
Aucun commentaire:
Enregistrer un commentaire