C++ for loop in my code not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

C++ for loop in my code not working

Sorry my for loop not working (line 46), can anyone enlighten me? https://code.sololearn.com/cyoZC0Oo06Nu/?ref=app

9th Nov 2018, 1:20 PM
Gordon
Gordon - avatar
5 Answers
+ 5
The mistake is indeed hard to spot. I handtraced it to line 24 though. Go through your function with 100 as the argument. You'll notice that in line 24, you indirectly divide by 0 - remainder needs division - and thus the program stops working. You should make an extra else-if case that covers 0.
9th Nov 2018, 1:39 PM
Shadow
Shadow - avatar
+ 3
Interesting I'm trying for a while I found out something it's if who is disturbing and if covers function
9th Nov 2018, 1:33 PM
Roneel
Roneel - avatar
+ 2
line 49 is added to check whether the problem is with for loop or with the function isGapful, thus the output looks weird.
9th Nov 2018, 1:49 PM
Gordon
Gordon - avatar
+ 1
Yep if we start from 101 it works weirdly but works edit: because of other cout i
9th Nov 2018, 1:44 PM
Roneel
Roneel - avatar
+ 1
Thanks for finding out that the problem occur at line 24. I should use n2=n2/10 at line 11.
9th Nov 2018, 1:46 PM
Gordon
Gordon - avatar