There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:
Why do you have "sum = sum + data" on line 26? At this point, you know data must be zero, so this is an unnecessary line.
Finally, you get the square of the total because that is exactly what this code says to do:
sum2 = Math.pow(sum, 2);
What you need to do is compute the square of each number as you get it, and add that to your sum2 (and PLEASE choose a better name, like "sumOfSquares").
I also need to calculate the mean and by using that I was able to do so.
so please excuse me for not thinking to use a for loop in this problem.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Paul Clapham wrote:Then perhaps your problem is that you read in the numbers that the user inputs, but you don't store them anywhere so that you can go through them a second time to calculate the standard deviation?
Peter Haugen wrote:So, I have tried to take your advice about sitting down and writing everything out. This is what I have come up
Please forgive my lack of knowledge here, but I thought that "data" stored them...
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Peter Haugen wrote:So, I have tried to take your advice about sitting down and writing everything out. This is what I have come up... At this point I am having issues calculating the deviation... Could anyone please help?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Peter Haugen wrote:Thanks everyone for the help with this problem.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors