You should be testing what estimatedQuality
returns, not performing the test before calling it.
double pricePerUnit(int x, int y) {
int quality = estimatedQuality(x, y);
double price;
if (quality < 2) {
price = 0.5;
} else if (quality < 4) {
price = 0.75;
} else if (quality == 4) {
price = 1;
} else if (quality == 5) {
price = 2;
}
return price;
}
You can do it with a switch
like this:
double pricePerUnit(int x, int y) {
double price;
switch(estimatedQuality(x, y)) {
case 0:
case 1:
price = 0.5;
break;
case 2:
case 3:
price = 0.75;
break;
case 4:
price = 1;
break;
case 5:
price = 2;
break;
}
return price;
}