Equivalent gore, without shitty variable names or nested ternaries.
int changeVolume(int currentVol, bool up) {
int adjustment;
if (currentVol % 2 == 0) {
//is even
int adjustOneModResult;
if (up) {
//we increment one only if we're on 4, 14, 24, etc ...
adjustOneModResult = 4;
} else {
//we decrement one only if we're on 6, 16, 26, etc ...
adjustOneModResult = 6;
}
if (currentVol % 10 != adjustOneModResult) {
// even, not on 4, 14, 24 if going upwards, and not on 6, 16, 26 if going downards
if (up) {
// even, going upwards, and not on 4, 14, 24, etc ...
adjustment = 2;
} else {
// even, going downards, and not on 6, 16, 26, etc ...
adjustment = -2;
}
} else {
// even, on 4, 14, 24 if going upwards, or on 6, 16, 26 if going downards
if (up) {
// even, going upwards, on 4, 14, 24, etc ...
adjustment = 1;
} else {
// even, going downards, and on 6, 16, 26, etc ...
adjustment = -1;
}
}
} else {
//is on odd multiple of 5
if (up) {
// is on odd multiple of 5 going upwards
adjustment = 1;
} else {
// is on odd multiple of 5 going downwards
adjustment = -1;
}
}
return currentVol + adjustment;
}