j == 0;
At this point,
j
is uninitialized.
If j
just happens to be zero, then this will be an infinite loop. Your loop shouldn't terminate when
j != 0
(which is what it currently says). I think what you want to do is start
i
at
inp.length ()-1
(last character) and move
i
to
(first character). As such, you should terminate the loop when
i
becomes less than zero.
pow ((float) base-48,j)
I went over this in my last post but I was wrong.
base-48
works because
base
is a
char
, though why don't you just declare
base
as an
int
so you don't have to subtract 48.
(inp[i]-48)
On the subject of 48, it's a magic number. You should do
inp[i] - '0'
instead. This goes the same for above,
pow ((float) base - '0',j)
though like I said you should just make
base
an
int
Your main issue is with your for loop header. This is what you should be doing:
shacktar wrote: |
---|
You should start i at inp.length()-1 and j at zero. You should terminate when i becomes less than zero, and you should be incrementing j and decrementing i . |
If you use a for loop, then you will be initializing
i
and j
as well as incrementing
j
and decrementing
i
. This wouldn't follow the basic
for(T i = 0; (some condition); i++)
structure. You may want to implement the above using a while loop instead if you can wrap your head around it better.