There you are, as I was tracking the code it looked in the first example that the Variance was written down wrong.
A couple of notes on presentation:
1 - Currently you have no comments, shove in a few here and there.
2 - The variable names are very unclear - why not just use "average" and "variance" for av and a?
3 -
I'm not good on telling languages apart, I only work in C++ (and when I say "work", I mean steal other people's code and make token changes to it, but anyway...), but it looks like you must be using an inbuilt average calculation because nowhere is there a hand-written code for calculating the average. I think if I were marking this program I'd expect people to write something like the following (though this is in C++ and so is just a guide):
double average=0;
double sum = 0;
for (int i = ; i< numvals; i++)
{
sum = sum + val.add(i) ;
//This code probably would fail but I'd be trying here to add each value to the sum in turn.
//I've only used the val.add(i) thing so that it's clear which part of the program you wrote I'd be wanting to use here.
}
average = sum/(numvals+1); //Or just use val.count but you know what I mean.
//Also note the heavy use of line breaks to space the code out.
The other thing is that at the moment the code seems very inflexible - to calculate the mean and variance for a new set of values seems to involve inputting the fresh data into the code by hand. That's going to have to be changed, not sure how. Might need to call data from some file or other, that would be the easiest. Don't ask me how to do this!
Anyway good to see you have the correct output result for the Variance, at least that's the maths of the program sorted.