Mean using For loop

I have been tasked with finding the number of arguments, the mean, and variance of a vector that a user inputs. So far I have been able to figure out how to check for the amount of arguments but i cannot figure how to do the variance. I know I have to use a for loop but im not sure how to do it. Any help would be nice.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 #include <iostream> 
#include <vector>

int main (int argc, char** argv) {
	float a;
	std::vector <float> v;
		std::cout << "Enter numbers\n";
		while(std::cin>>a){
			v.push_back(a);
		}
	

	for(std::vector<float>::iterator i=v.begin();i==v.end();++i){
		

	}
	
	std::cout<<"There were "<<v.size()<<" numbers.\n";
    for(float&i:v)
        ;
    float sum=0;
    for(int n : v)
        sum += n;
    
    std::cout<<"sum="<<sum<<"/n";
    
    float avg; 
    avg=sum/v.size();
    std::cout<<"The mean of these numbers is "<<avg<<"/n";
    
}

Last edited on
Topic archived. No new replies allowed.