Thread: [Dev-C++] why doesn't my program work...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: chromatonus 7. <chr...@ho...> - 2001-09-30 21:57:45
|
//hi, this is my program, there's no error, just that it's supposed to //calculate the mean and standard deviation of a list of data. after I input //my list the program exits without showing either of the two values. //If anyone can help, it will be much appreciated : ) //Mean and Standard Deviation //9-20-01 #include <iostream.h> #include <conio.h> #include <math.h> #include <stdlib.h> //Prototypes int enter( int dat[] ); float average( int dat[], int n ); float stndrdv( int dat[], int n, float ave ); void display( int size, float ave, float sd ); int main() { int size; int dat[100]; float ave; float sd; size = enter( dat ); ave = average( dat, size ); sd = stndrdv( dat, size, ave ); } int enter( int dat[] ) { int k; //counter for how many values entered int x; //individual values entered int size; k = 0; cout<< "Statistic evaluator" << "\n"; cout<< "The first datum on the list= "; cin>> x; while( x != 0 ) { dat[k] = x; k++; cout<< "and the rest of the list goes "; cin>> x; } return(k); } float average( int dat[], int k ) { int j; //loop counter int sum; //sum of the y vals float ave; sum = 0; for( j=0; j<k; j++ ) sum = sum + dat[j]; ave = (float)(sum/k); return( ave ); } float stndrdv( int dat[], int k, float ave ) { int i; //loop counter float p; //variance*size: the sum float sd; p = 0; for( i=0; i<k; i++ ) p = ( dat[i] - ave )*( dat[i] - ave ) + p; sd = (float)(sqrt( p/(k-1) )); return( sd ); } void display( int size, float ave, float sd ) { cout<< "size=" << size << "\n"; cout<< "mean=" << ave << "\n"; cout<< "s.d.=" << sd << "\n"; system("PAUSE"); } _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp |
From: St0fF 6. <st...@gm...> - 2001-09-30 22:48:16
|
Sorry, Dude! This looks like real beginner's stuff. You just forgot to call your = void display(). I changed it for you. Hopefully these are your very first steps. If it's not, I strongly = suggest you finding a programming partner, so you shouldn't have needed = to put a question to a mailinglist about one missing line (that does all = the things that were missing for your program to run as you expected = ...). fullfilled with hope, St0fF. ----- Original Message -----=20 From: "chromatonus 712" <chr...@ho...> To: <dev...@li...> Sent: Sunday, September 30, 2001 11:57 PM Subject: [Dev-C++] why doesn't my program work... | //hi, this is my program, there's no error, just that it's supposed to | //calculate the mean and standard deviation of a list of data. after I = input | //my list the program exits without showing either of the two values. | //If anyone can help, it will be much appreciated : ) |=20 |=20 | //Mean and Standard Deviation | //9-20-01 |=20 | #include <iostream.h> | #include <conio.h> | #include <math.h> | #include <stdlib.h> |=20 | //Prototypes | int enter( int dat[] ); | float average( int dat[], int n ); | float stndrdv( int dat[], int n, float ave ); | void display( int size, float ave, float sd ); |=20 |=20 | int main() | { | int size; | int dat[100]; | float ave; | float sd; |=20 | size =3D enter( dat ); | ave =3D average( dat, size ); | sd =3D stndrdv( dat, size, ave ); display(size,ave,sd); | } |=20 |=20 | int enter( int dat[] ) | { | int k; //counter for how many values entered | int x; //individual values entered | int size; |=20 | k =3D 0; | cout<< "Statistic evaluator" << "\n"; | cout<< "The first datum on the list=3D "; | cin>> x; | while( x !=3D 0 ) | { | dat[k] =3D x; | k++; | cout<< "and the rest of the list goes = =20 | "; | cin>> x; | } | return(k); | } |=20 |=20 | float average( int dat[], int k ) | { | int j; //loop counter | int sum; //sum of the y vals | float ave; |=20 | sum =3D 0; | for( j=3D0; j<k; j++ ) | sum =3D sum + dat[j]; | ave =3D (float)(sum/k); | return( ave ); | } |=20 |=20 | float stndrdv( int dat[], int k, float ave ) | { | int i; //loop counter | float p; //variance*size: the sum | float sd; |=20 | p =3D 0; | for( i=3D0; i<k; i++ ) | p =3D ( dat[i] - ave )*( dat[i] - ave ) + p; | sd =3D (float)(sqrt( p/(k-1) )); | return( sd ); | } |=20 |=20 | void display( int size, float ave, float sd ) | { | cout<< "size=3D" << size << "\n"; | cout<< "mean=3D" << ave << "\n"; | cout<< "s.d.=3D" << sd << "\n"; | system("PAUSE"); | } |=20 |=20 |=20 |=20 | _________________________________________________________________ | Get your FREE download of MSN Explorer at = http://explorer.msn.com/intl.asp |=20 |=20 | _______________________________________________ | Dev-cpp-users mailing list | Dev...@li... | https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
From: Ivan F. <fr...@gc...> - 2001-10-01 18:41:20
|
You forgot to call display in main. --Ivan Frohne ----- Original Message ----- From: "chromatonus 712" <chr...@ho...> To: <dev...@li...> Sent: Sunday, September 30, 2001 13:57 Subject: [Dev-C++] why doesn't my program work... > //hi, this is my program, there's no error, just that it's supposed to > //calculate the mean and standard deviation of a list of data. after I input > //my list the program exits without showing either of the two values. > //If anyone can help, it will be much appreciated : ) > > > //Mean and Standard Deviation > //9-20-01 > > #include <iostream.h> > #include <conio.h> > #include <math.h> > #include <stdlib.h> > > //Prototypes > int enter( int dat[] ); > float average( int dat[], int n ); > float stndrdv( int dat[], int n, float ave ); > void display( int size, float ave, float sd ); > > > int main() > { > int size; > int dat[100]; > float ave; > float sd; > > size = enter( dat ); > ave = average( dat, size ); > sd = stndrdv( dat, size, ave ); > } > > > int enter( int dat[] ) > { > int k; //counter for how many values entered > int x; //individual values entered > int size; > > k = 0; > cout<< "Statistic evaluator" << "\n"; > cout<< "The first datum on the list= "; > cin>> x; > while( x != 0 ) > { > dat[k] = x; > k++; > cout<< "and the rest of the list goes > "; > cin>> x; > } > return(k); > } > > > float average( int dat[], int k ) > { > int j; //loop counter > int sum; //sum of the y vals > float ave; > > sum = 0; > for( j=0; j<k; j++ ) > sum = sum + dat[j]; > ave = (float)(sum/k); > return( ave ); > } > > > float stndrdv( int dat[], int k, float ave ) > { > int i; //loop counter > float p; //variance*size: the sum > float sd; > > p = 0; > for( i=0; i<k; i++ ) > p = ( dat[i] - ave )*( dat[i] - ave ) + p; > sd = (float)(sqrt( p/(k-1) )); > return( sd ); > } > > > void display( int size, float ave, float sd ) > { > cout<< "size=" << size << "\n"; > cout<< "mean=" << ave << "\n"; > cout<< "s.d.=" << sd << "\n"; > system("PAUSE"); > } > > > > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |