• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

summing elements of array and getting strange behavior

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Ok, this isn't a school assignment...just a random exercise I found on the internet since I'm beginning to learn a bit about arrays. For my version, user enters the number of indexes the array will have, and then enters data for the elements, and we output the sum. The sort of tricky part (part of the exercise I suppose is thinking about primitive variables) is that the input for elements should be a char representing a single integer and output should be in terms of a long. Again, not really sure why because I would not go about the task this way...but I want to complete the exercise per instructions as a learning experience.

The program below compiles fine. However, let's say I chose 1 index for my array, and enter 1 as my element..the program returns 49. If I chose 1 index and enter 2 as my element, it returns 50...and so on according to pattern. My question is first can you point me in the direction of where I'm going wrong? Second, I guess this is more theoretical, any ideas for why it is beginning at 49?

Here is my code:



Thanks in advance for your help
 
Ranch Hand
Posts: 75
Android Chrome Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's giving the Ascii char value.

http://www.asciitable.com/

 
Bill Suttle
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome Aj, thanks!

Bill
 
I brought this back from the farm where they grow the tiny ads:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic