Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# Calculation Change in numbers

Matt Deg
Greenhorn
Posts: 7
I need to calculate the change in certain values of numbers I have put asterisks around where I need help with the numbers I am using are
1112365 5567821 1234677
3000765 7563460 954680
4012765 12123225 883452
5674780 17192360 755242
10680140 26075960 663459

So in the specified area I need the program to calculate change going down the column, I don't need the changes to be listed I only need the average change in the end....right now I know the code for that part is nowhere near right...any help would be much appreciated...

Paul Clapham
Sheriff
Posts: 21416
33

Well, I can't quite tell what your code is supposed to be doing; probably if I read the instructions carefully I could figure it out, but let's start with what you did:

If I'm not mistaken, what you have in the brackets at the right-hand end involves subtracting a number from itself. And that always produces zero. So whatever you were trying to do with that code, that isn't right.

Matt Deg
Greenhorn
Posts: 7
Thank you and what I need to be doing there is i believe calculate the total change in numbers between the 5 numbers...so for the first group the average change between the number 1112365, 3000765, 4012765, 5674780, 10680140....essentially what the idea is we are to calculate the average change in the members that use a particular site, the numbers represent the users in 5 different years....this is similar to what i need it to produce
The program would produce output similar to: The asterisked line is what i need the specified section of my code to produce but with the numbers i provided instead of the numbers below...let me know if any further clarification is need, I will try to explain it better

Welcome to Growth Statistics ...
a program to calculate the growth in a
social media Web site over five years.

13-24 25-54 55+
----- ----- -----
2005: 100 100 100
2006: 200 100 100
2007: 300 100 100
2008: 400 200 100
2009: 500 300 100
----- ----- -----

Avg change: 100 60 20 *********************

Programming exiting.

Note: for category 13-24 the average is (100+100+100+100+100)/5 == 100;
for category 25-54 the average is (100+0+0+100+100)/5 == 60;
and for category 55+ the average is (100+0+0+0+0)/5 == 20;

Paul Clapham
Sheriff
Posts: 21416
33
Matt Deg wrote:what I need to be doing there is i believe calculate the total change in numbers between the 5 numbers...so for the first group the average change between the number 1112365, 3000765, 4012765, 5674780, 10680140....

Okay. So Java and computers aside, if you only had a pencil and paper, how would you do that calculation for the five numbers you showed there?

Matt Deg
Greenhorn
Posts: 7
Change = x2-x1 , but I'm not sure how to make that work with my loop, from my very limited understanding of what I am doing I can only work as the loop is running is the previous change and the new number, I don't know how or if I can use the number from the previous loop

Matt Deg
Greenhorn
Posts: 7
Never mind I think I have it, sorry not very good at this stuff, although I may need help printing the table at the end of the program

Matt Deg
Greenhorn
Posts: 7
This is the code as far as I have gotten it, now I need to make a nice neat table, for which I can't get my values to print from my array, or the years to print out vertically, it should look like this...more or less I really just want some form of it to print...again asterisks around the problem area...Thank you
13-24 25-54 55+
----- ----- -----
2005: 100 100 100
2006: 200 100 100
2007: 300 100 100
2008: 400 200 100
2009: 500 300 100
----- ----- -----

Avg change: 100 60 20