Help fix final code please :*(

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
It converts the two operands to base 10 fine and does the arithmetic operation, but why doesnt the final answer get converted to base 6? The code to convert the answers is all way at end.
 

MSCoder610

Senior member
Aug 17, 2004
831
0
71
Have you tried compiling with -Wall and eliminating all the warnings you get? I compiled that code and get several, most notably '____ might be used uninitialized' warnings. For example in ConvertoDeci counter has no initial value, but you start incrementing it like you initialized it to zero. I changed those warnings and the program seems to work fine for me (I think).
 

MSCoder610

Senior member
Aug 17, 2004
831
0
71
Nevermind, with your compiler it probably already initialized it to zero. I tried 35+35 and it says 70(dec) but 10(base 6) which is obviously wrong. The basic problem is that you're finding the base 6 digits correctly, but then just adding them to result (with no place value). You did it correctly with the decimal conversion, so do something similar:
...
result += (num % 6) * pow(10,counter++);
...
 

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
Originally posted by: MSCoder610
Nevermind, with your compiler it probably already initialized it to zero. I tried 35+35 and it says 70(dec) but 10(base 6) which is obviously wrong. The basic problem is that you're finding the base 6 digits correctly, but then just adding them to result (with no place value). You did it correctly with the decimal conversion, so do something similar:
...
result += (num % 6) * pow(10,counter++);
...

I got an overflow error T.T
 

Atheus

Diamond Member
Jun 7, 2005
7,313
2
0
You want ConverttoHex(); to give a base-6 number? You know hex is base 16 right? If you want hex your program would have to know how to use the letters A-F for decimals 10-15.
 

MSCoder610

Senior member
Aug 17, 2004
831
0
71
Hexadecimal is 16, I guess hex would be 6 (although people abbreviate hex for hexadecimal so that's confusing).

Anyway, I don't know where you'd be getting an overflow error, assuming you did 'int counter = 0' at the beginning of that function. There's plenty of other ways to keep track of the place value (like having an int variable starting = 1, and multiplying it by 10 each iteration, and multiplying that by the current digit and adding it to result).