0

I think I need a second pair of eyes to take a look at this as I can't see what I'm doing wrong :-(

I'm trying to get the bigesst value using a simple function, but the results are not what I'm expecting.

Here is the code...

pragma solidity ^0.4.21;

contract GetBiggest {

uint public val1 = 1;
uint public val2 = 2;
uint public val3 = 3;
uint public val4 = 0;



        function getBiggestValue() public view returns(uint) {

            uint x = val1;


            if(x < val2) {
                    x = val2; 

                }

            if(x < val3) {
                    x = val3; 

                }

            if(x < val4) {
                    x = val4; 

                }

        }

}

I'm expecting the value of 3 to be returned when I call the function, but I get 0

What's up with this?

thanks

  • Where's the return statement??? I wonder how this code even compiles... – goodvibration Apr 30 '18 at 9:32
  • @goodvibration The code compiles because there is a default value set for every typecast. – ReyHaynes Apr 30 '18 at 14:19
1

You are simply missing the return x; statement at the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.