• Post Reply Bookmark Topic Watch Topic
  • New Topic

Values in array not stored?  RSS feed

 
Damien Sky
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind, I just forgot to increment n while trying to store the humidity... I do this every time and I suddenly realize what I did wrong when I post it online...

My problem is that after printing humidity[n] in the "Humidity(%)" row, it seems that humidity[n] becomes 0. I checked like this:



In the "Humidity(%)" row, they come out fine, but when I do this, they come out as 0, which I think would explain why my heat indices are consistently lower than the temperature when the temperature is over 80.

My code:

 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for keeping up your code and using code tags. Can I make a suggestion about your code?

The general rule is not to have line over 80 characters. This seems short, but it help in a lot of situations.

Lines 78 and 79 are both long and cryptic. The use of "magic numbers" is discouraged. A magic number is one that isn't patently obvious (e.g. 1/2) that is not explained or better yet, stored in a variable. -42.379 may mean something to you, but it doesn't to me.

"tempDoubleArray[]" is not a good name. I can tell it's a double array by looking at the code. What does it do? What is it for?

 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damien Sky wrote:Nevermind, I just forgot to increment n while trying to store the humidity... I do this every time and I suddenly realize what I did wrong when I post it online...


It's the action of of mentally constructing your question that gives your brain a chance to analyse the problem.
I get this all the time when I present a problem I've encountered to a colleague and, just as I'm getting to the end of explaining the problem, go "Ah! That's it!".
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote: . . . . A magic number is one that isn't patently obvious (e.g. 1/2) . . .
Agree. It is much quicker to write 0.
 
Damien Sky
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was just the formula I was given.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damien Sky wrote:That was just the formula I was given.


Fair enough, but you can still break it into smaller lines and format it a bit. Long lines in programs mess up the screen for some users and they're hard to read.

 
Damien Sky
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. I understand that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!