I know the simple way to calculate the average
but I created a table there are 2 columns one is x and the other one is x^2
and the more numbers I type in x it squares them
I wanna know how you can take the average of x and x^2
Firstly, I do not think you can have "float x^2" - ^ is an operator & hence should cause an error, try calling the variable just "x2".
Secondly, on the line "x^2 = x*x.;" - there is a stray "." just remove that & that should work fine.
Thirdly, if you want to take the average I recommend that you create some new variables:
Have a variable to store the running average of x
Have a variable to store the running average of x squared
Have a variable that counts how many numbers have been entered.
From there you should be able to calculate the average - the above variables should be edited in the loop.
hmm ok but how am i gonna have a variable to store the running average of x
Have a variable to store the running average of x squared
Have a variable that counts how many numbers have been entered.
I couldnt figure that out
I see also that you want a RUNNING average of x. That should be very easy for you to add into the above example. See if you can do it by yourself. If not, we'll take it further. Here's a hint...
change "average" in the above example to equal the running total of x, and then divide that by 2.
Then just create a variable called "count" and do this within the loop...
1 2
count++;
average += (runningtotal / count);
Make sure to initialize count to zero.
This or any variation thereof will give you whatever you want. Whatever your desired outcome, this is very simple to construct. You should be able to modify these variables to suit whatever number you want to come up with.
Thank you so much I actually learned how to it but I have one more question how can i take that average column and make it a row and put it under that loop??