Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org error when finding the standard deviation of a vector
 User Name Remember Me? Password
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 10-25-2005, 10:44 PM #1 mshinska LQ Newbie   Registered: Oct 2005 Posts: 14 Rep: 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 ( - average)' cannot be used as a function my code that gets the error is: #include #include #include using namespace std; int main(void) { vector 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; }
 10-25-2005, 10:50 PM #2 mshinska LQ Newbie   Registered: Oct 2005 Posts: 14 Original Poster Rep: i forgot to add this when i copy/pasted float average; float sum; for (int i = 0; i
 10-25-2005, 10:52 PM #3 dmail Member   Registered: Oct 2005 Posts: 970 Rep: what does this line do? Code: `sum2 = ((sum2) + (values[f]-average)(values[f]-average) )` whats "average" and what is "(values[f]-average)(values[f]-average)" do? just seen you post, i still dont know what the second part does tho. Code: ```i forgot to add this when i copy/pasted float average; float sum; for (int i = 0; i
 10-25-2005, 11:01 PM #4 mshinska LQ Newbie   Registered: Oct 2005 Posts: 14 Original Poster Rep: 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 Last edited by mshinska; 10-25-2005 at 11:03 PM.
 10-25-2005, 11:05 PM #5 dmail Member   Registered: Oct 2005 Posts: 970 Rep: you seem to be missing the point, or i am. is this some macro magic or something Code: `(values[f]-average)(values[f]-average)` what does this evaluate to? is there susposed to be an operator in there?
 10-26-2005, 12:03 AM #6 mshinska LQ Newbie   Registered: Oct 2005 Posts: 14 Original Poster Rep: oh i get what you are saying i forgot the multipication symbol (*), thank you for your help it works now!!!!