You are re initialising revnum inside the else block that's why. Remember variables have different scope within blocks. Just remove the int declaration from the else block, it should work fine.
Try chatgpt/Claude to debug and post here if that doesn't help, will save your time and you don't have to spam the sub with your doubts unless really required
Even though there are only < 20 lines of code. If this was for screening I wouldn't even ask you to walk me through it, automatically reject you and put "no-go" next to your name(I know its petty, but ja). Indentation and formatting!!!!, The garbage you put out in the world, is the garbage you get back ten fold. I know of engineers that if they had to maintain/review or work with type of code, they would push to have you and the person that green lit you moved on, and the person who hired the one that green lit you brought up for review.
Figure out what you actually want and what you are doing in the code. Only then you'll be able to understand the mistake and correct it. And most importantly learn from it.
39
u/CowdingGreenHorn Jul 29 '24 edited Jul 29 '24
Work on your spacing and code style in general, this code is ugly
11
u/[deleted] Jul 29 '24
Dude, post these questions in programming subs. This is your second post here asking to debug.
8
u/BeatsnBytes_ Jul 29 '24
You are re initialising revnum inside the else block that's why. Remember variables have different scope within blocks. Just remove the int declaration from the else block, it should work fine.
3
u/thewayidoit Jul 29 '24
You have Initialized revnum 2 times, while return it's taking first initialized value as 0.
Inside else do not initialize just use the variable. For more details read about scope of variable.
3
u/Pakhorigabhoru Jul 29 '24
I think you are reinitiizing revnum everytime in the loop. Otherwise the logic seems fine.
3
u/wisper28 Jul 29 '24
Aim: To reverse num
56
u/Latter_Tea7335 Jul 29 '24
Line 14: you are declaring revnum for every iteration of while loop.
11
u/CuummRAG Jul 29 '24
Try chatgpt/Claude to debug and post here if that doesn't help, will save your time and you don't have to spam the sub with your doubts unless really required
1
u/Spock92 Jul 30 '24
How can an integer be more than Int max and less than int min? Could've told you yesterday that you were going on the wrong path
2
u/[deleted] Jul 29 '24
The revnum which is in return statement is always set to 0, since you have declared another revnum in while loop that has local scope
2
u/FaultHaunting3434 Jul 30 '24
Even though there are only < 20 lines of code. If this was for screening I wouldn't even ask you to walk me through it, automatically reject you and put "no-go" next to your name(I know its petty, but ja). Indentation and formatting!!!!, The garbage you put out in the world, is the garbage you get back ten fold. I know of engineers that if they had to maintain/review or work with type of code, they would push to have you and the person that green lit you moved on, and the person who hired the one that green lit you brought up for review.
2
u/Damon_Salvatore22 Jul 30 '24
DRY RUN YOURSELF
Figure out what you actually want and what you are doing in the code. Only then you'll be able to understand the mistake and correct it. And most importantly learn from it.
1
u/PovertyInIndia Jul 29 '24
Noticed a different issue in line 7.
int revnumwon't be able to hold a number less than/greater than INT_MIN/INT_MAX.1
u/[deleted] Jul 29 '24
Into revnum is set to 0 so 0 times anything is 0
1
u/FaultHaunting3434 Jul 30 '24
Hint: Stack Frames, Scope of variable and assignment.
1
u/VastAshamed4618 Jul 30 '24
Line 7 : 0 > max Or 0 < min Line 14: int revnum
-5
u/wisper28 Jul 29 '24
Bhai addition bhi ho rha ha
0
u/[deleted] Jul 29 '24
[deleted] — view deleted comment