• Post Reply Bookmark Topic Watch Topic
  • New Topic

Armstrong Numbers. Program giving o as output all the time.  RSS feed

 
Ranajoy Saha
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'd suggest is printing out the values of sum and number just before line 27. Are they equal to what you think they should be? When you realise they aren't, it should be fairly obvious why.

Edit: oh, and that comment applies to the previous version of your code that you've just removed. But the same principle applies. Find out what the actual values are, either by using a debugger or a print statement. Compare them to calculations you've done by hand.

Second edit: the main reason it's printing zero is that you're printing out a variable you never set!
 
Ranajoy Saha
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You! I never saw what I was printing. What a fool I am. Thanks for correcting me!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!