0

If statements break the code

I was working on the Fisherman code challenge and, after writing the whole thing and trying to test it, nothing would show up. After commenting almost the whole code, it was finally able to output the number you entered. I am providing the code and you can try to uncomment the if statements. If anyone has any fix/explanation, it would be appreciated. https://code.sololearn.com/c3IUT43BklHC/?ref=app

2nd Aug 2018, 5:58 PM
Alexandru Turculet
Alexandru Turculet - avatar
7 Respostas
+ 4
I agree you should use brackets, not just to improve readability, it'll bite you one day, but your choice. But that's not the problem today... probably, haven't read through the code too much :) for(int i=0; i*i<=a; i++) if(a%i==0) ... See it yet? a%0 is a division by 0 which results in an error.
2nd Aug 2018, 6:24 PM
Dennis
Dennis - avatar
0
please us {} in if statements and use meaningful names for your variables. To work use isFisher(a)==0 or 1 in the if statement. Why you give b a value when you input it in the next line?
2nd Aug 2018, 6:03 PM
B K
0
Borislav Kalinski In C++ you don't need to use brackets whenever you only have 1 line inside and if the output is eother 0 or 1 you don't need to check, because 0 means false and 1 means true.
2nd Aug 2018, 6:10 PM
Alexandru Turculet
Alexandru Turculet - avatar
0
Borislav Kalinski I do that incase there's only 1 input, also, if you want to add more suggestions please write a new comment, as it's hard to check if you edit your own
2nd Aug 2018, 6:13 PM
Alexandru Turculet
Alexandru Turculet - avatar
0
https://github.com/borislavvv00 Check my acount to see my works if you want. Yes you can write without brackets but is it not readable i mean check the standarts.
2nd Aug 2018, 6:13 PM
B K
0
Borislav Kalinski Sorry, I'm really not experienced with working with other people, so I don't really know how github works. As for the readability, I find it easier on the eyes without the brackets when the indentation is right.
2nd Aug 2018, 6:15 PM
Alexandru Turculet
Alexandru Turculet - avatar
0
Dennis Wow, I can't believe I was that dumb. Anyways, thank you so much for the help.
2nd Aug 2018, 6:37 PM
Alexandru Turculet
Alexandru Turculet - avatar