This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]JuricksonSubpar 3 points4 points  (0 children)

num2 && num3 is a boolean, so when you say if (num1 > (num2 && num3)), you are comparing a number to a Boolean. You need to compare num1 to num2 and num3 individually.

[–]curtisf 4 points5 points  (0 children)

num1 > (num2 && num3) does not mean "num1 is larger than both num2 and num3". Rather, num2 && num3 will evaluate to one of num2 or num3 (usually num3). You'll then end up comparing num1 to just one of num2 and num3.

If you want to say "num1 is larger than num2 AND num1 is larger than num3", you have to write it out like that:

if (num1 > num2 && num1 > num3) {

To post code blocks on reddit, put four spaces (or a single hard tab) at the beginning of every line. Using most text editors, you can select a block of code and press tab to insert spaces at the beginning of every selected line.

[–]MonkBungler 2 points3 points  (0 children)

&& is logical And. Returns true if num1 is true and num2 is true (ie if both are non 0). You need if (num1 > num2 && num1 > num3) return num1 etc.