Can I make an if statement that changes depending on the return of a function?

I want to make an if statement that says, "If Y dimensions are okay, then use X function and return Z.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
double boxTester(){
                    double OK, tooHeavy, tooLarge, tooHeavyLarge;
                    if ((length + width + height <= 150)&&(weight <= 80)){
                               return OK;
                               }
                    if ((length + width + height <= 150)&&(weight > 80)){
                                return tooHeavy;
                                }
                    if ((length + width + height > 150)&&(weight <= 80)){
                                return tooLarge;
                                }
                    if ((length + width + height > 150)&&(weight > 80)){
                                return tooHeavyLarge;
                                }
                    }


Can I use an if function to test if the function returns a certain value? If so could I make a function in my class or would I have to test it in the main function?
Can I use an if function to test if the function returns a certain value


Surely you can, though "if" is not a function but a control structure

1
2
3
4
5
6
7
int sumDimension(int a, int b, int c) {
    // ...
}

if (sumDimension(length, width, height) <= 150 && weight <= 80) {
    // ...
}

If you mean this. However in your case it would be better to calculate sum of dimensions in separate variable before all these ifs - cal this variable "size" for example - and then use if (size <= 150) etc.
Topic archived. No new replies allowed.