• Post Reply Bookmark Topic Watch Topic
  • New Topic

Having trouble with odd results from octal-decimal converter  RSS feed

 
Mason Reeves
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I wrote this small program to take an octal number from the user and convert it to decimal form.


Some conversions work. For example, 77 will be correctly converted to 63, and 77777777 will be converted to 16777215. However, some conversions do not work. An example of this is 775002 gets converted to 74898. I'm not really sure where the problem is here. Any help would be greatly appreciated! Thanks everybody.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your 'remainder' is only calculated once. I haven't analyzed anything past that.
 
Mason Reeves
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! I moved the remainder initialization and calculation into the for loop and now it works perfectly! Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!