11
Jul 29 '24
Dude, post these questions in programming subs. This is your second post here asking to debug.
-19
u/wisper28 Jul 29 '24
If you wish you can help else skip no one bounded you to help
6
5
u/throwaway2492872 Jul 29 '24
Part of getting better is learning to debug. This is a really simple bug to figure out.
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.
4
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.
2
3
u/Pakhorigabhoru Jul 29 '24
I think you are reinitiizing revnum everytime in the loop. Otherwise the logic seems fine.
1
3
56
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
1
u/wisper28 Jul 30 '24
Nhi bhai vo thik ha this is part of code ,mistake was i declared revnum 2 time
1
u/Spock92 Jul 30 '24
The code looks very wrong on very different levels, but explain me logically about how can a integer be more or less than its max or min value?
1
2
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 revnum won't be able to hold a number less than/greater than INT_MIN/INT_MAX.
1
1
1
-5
0
Jul 29 '24
[deleted]
1
u/PaulRosenbergSucks Jul 30 '24
It doesn't matter, since the 'original num' is copied in anyway in C++. It's no different than any other local variable.
0
39
u/CowdingGreenHorn Jul 29 '24 edited Jul 29 '24
Work on your spacing and code style in general, this code is ugly