+ 1

I made a code using the "if" statement. The second use of it doesnt work. The code is the last code I made on my profile. Help?

I need a solution to fix a problem in a code. It wont show the problem. It's just not running it. It skips it. https://code.sololearn.com/crXvIi33H344/?ref=app https://code.sololearn.com/crXvIi33H344/?ref=app

28th Apr 2019, 1:49 AM
Danger
Danger - avatar
14 Réponses
+ 16
Check conditions (a>b) & (b<a) are identical, after correcting them program will work good
28th Apr 2019, 1:59 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 16
yes, you can use if else but in this case all the conditions are mutually exclusive & complete all possible cases so it will not affect the result. //but you will be free to not test the last condition, and directly print the last statement in else {} block, like : if(a>b) {} else if(b<a) {} else {} //here no need to write test condition (a==b) as its the only condition possible if other 2 are false.
28th Apr 2019, 2:24 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
I just saw that 😂😂😂 my uncle had to tell me
28th Apr 2019, 1:59 AM
Danger
Danger - avatar
+ 2
First off, sololearn codeground it's not a good get more than 1 value to do something in your code so please try it on your computer with a compiler
28th Apr 2019, 1:55 AM
Juan David Padilla Diaz
Juan David Padilla Diaz - avatar
+ 2
I fixed it so u can see how I wanted it cause I dont remember
28th Apr 2019, 2:09 AM
Danger
Danger - avatar
+ 2
Juan David Padilla Diaz Yes I would use else if, else also. However when helping new learners I prefer to help them fix their logic, rather than rewrite the logic for them.
28th Apr 2019, 2:18 AM
Jared Bird
Jared Bird - avatar
+ 1
I dont have a computer, sadly
28th Apr 2019, 1:57 AM
Danger
Danger - avatar
+ 1
If you have Android search on Google play store CXX droid it's a compiler of c++ for phones
28th Apr 2019, 1:58 AM
Juan David Padilla Diaz
Juan David Padilla Diaz - avatar
+ 1
Ok, so the second if needs fixing. Use > instead of < then it should work how you expect.
28th Apr 2019, 1:59 AM
Jared Bird
Jared Bird - avatar
+ 1
I'm not there yet. I just finished the if lesson
28th Apr 2019, 2:02 AM
Danger
Danger - avatar
+ 1
Ok
28th Apr 2019, 2:25 AM
Danger
Danger - avatar
0
Jared Bird instead I'd use an else condition
28th Apr 2019, 2:00 AM
Juan David Padilla Diaz
Juan David Padilla Diaz - avatar
0
Although the text then doesn't match up. Should the second statement be greater or less? Was your goal to print: First is bigger, or Second is bigger, or The same. (Or something to that effect?)
28th Apr 2019, 2:07 AM
Jared Bird
Jared Bird - avatar