Re: [Dev-C++] why doesn't my program work...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
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
>
|