I keep getting errors with my Boolean statement to affirm whether it is a triangle or not, please help with the formatting.
How to program the Boolean statement, getting error
Resolved
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
13 December 2018, 16:50
To solve just follow these steps:
1) remove the semicolon ( ; ) at the end of line 19
2) Get rid of lines 20, 21,22, and 23. These are all unnecessary. This would make line 19 sit on top of 24 when they are all removed.
+1
Guadalupe Gagnon
13 December 2018, 16:58
Now as far as code goes:
line 21 has an error in that you are trying to set the value to true, but the double equal sign (==) is a comparison operator and not an assignment operator.
On line 23 you can just write the variable if(triangle) instead of if(triangle == true). This is because if() is checking for boolean values true or false. You declare the variable triangle to be a boolean of (disregarding the error) true.
if-else statements only need code blocks if they are to execute more than 1 statement. If you have 1 and only 1 statement, then the block is unnecessary. Now it is not against any rule to add blocks if you don't need them, but keeping your code small (within reason) is desirable. It really would be your preference, but you can write your code like this:
+1
Michael Martin
13 December 2018, 13:05
You have a semi-colon (;) after your if statement. You need to remove that. Also, if you declare a variable in a block (like you have declared boolean triangle) you won't be able to access it outside of the block.
+1
Darko Jakimovski
13 December 2018, 10:56
You cannot start the boolean expression like that. You need to consider the precedence of the parentheses, first you need to check the addition of the two, and then check if the sum is less or more. Hope this helps. Skol!
+1