error when finding the standard deviation of a vector
I keep getting this error, which i have never seen before:
lab10.cpp: In function `int main()': lab10.cpp:50: `sorry, not implemented: `float_expr' not supported by dump_expr (<expression error> - average)' cannot be used as a function my code that gets the error is: #include <iostream> #include <vector> #include <cmath> using namespace std; int main(void) { vector<int> values; int input; cout << "Enter a number: "; cin >> input; while(!cin.fail()) { values.push_back(input); cout << "Enter a number: "; cin >> input; } int f; float stdDev; float sum2= 0.0; for (int f=0; f < values.size(); f = f+1) { sum2 = ((sum2) + (values[f]-average)(values[f]-average) ); } sum2 = sum2/ values.size(); stdDev=sqrt((sum2)); cout << "The standard deviation is: " << stdDev << endl; return 0; } |
i forgot to add this when i copy/pasted
float average; float sum; for (int i = 0; i<values.size(); i = i + 1) { sum = sum + values[i]; average = sum/ values.size(); } |
what does this line do?
Code:
sum2 = ((sum2) + (values[f]-average)(values[f]-average) ) just seen you post, i still dont know what the second part does tho. Code:
i forgot to add this when i copy/pasted |
standard deviation is the square root of (each element - mean)^2 added together divided by the number of elements
for example if you have a vector of [ 1 2 3] the standard deviation is sqrt( ( (1-2)^2 + (2-2)^2 + (3-2)^2)/3) i explained average in my first correction |
you seem to be missing the point, or i am.
is this some macro magic or something Code:
(values[f]-average)(values[f]-average) |
oh i get what you are saying i forgot the multipication symbol (*), thank you for your help it works now!!!!
|
All times are GMT -5. The time now is 04:36 PM. |