standard deviation and skew. due today

my program is almost complete, however i have two problems. im not quite sure if i did the standard deviation and skew formulas right. it works for most things it seems, but for some reason if i type in for example 1,1,1 as the input, it says badly skewed? is that right? and same goes for if i type in 1,3,30. how ever it works wiht the examples given, 1,2,30; and 1,2,3.

i also need to make the program combatible with up to 10000 inputs, ending when the user types in cntrl^D instead of an input.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <cmath>
#include "arrayUtils.h"

using namespace std;
//*Determine if the given set of  value creates a skewed graph or not
// Determine if a data set is skewed
void skew ()
{//***set array to proper size;
    int size=3;
double datapoint;
                        /*input data;
                            ask for how many data entries there are;
                            ask for data entries;*/

                   //***set array to proper size;
double* data = new double [size];
                //***input and store data into array;
for (int i=0; i<size;i++){
//int arrayofdata (size);
//***input and store data into array

    cin>>datapoint;
    data[i]=datapoint;

}//***order array into ascending order;
//order function
// Step through each element of the array
for (int nStartIndex = 0; nStartIndex < size; nStartIndex++)
{
    // nSmallestIndex is the index of the smallest element
    // we've encountered so far.
    int nSmallestIndex = nStartIndex;

    // Search through every element starting at nStartIndex+1
    for (int nCurrentIndex = nStartIndex + 1; nCurrentIndex < size; nCurrentIndex++)
    {
        // If the current element is smaller than our previously found smallest
        if (data[nCurrentIndex] > data[nSmallestIndex])
            // Store the index in nSmallestIndex
            nSmallestIndex = nCurrentIndex;
    }

    // Swap our start element with our smallest element
    swap(data[nStartIndex], data[nSmallestIndex]);
}



//***order array into ascending order;for (int i=0; i<size; i++){



  //****use given formula to find mean (average);
 int total=0, average;
for (int b=0; b<size; b++){
    total=total+data[b];}
    average=total/size;


//****use given formula to find median;
float median;
float temp;
if(size%2==0)
median=(data[size/2]+data[size/2-1])/2;
else
median= data[size/2];
//use formula to find the standart deveation
double sdtotal=0;
for (int i=0; i<size; i++){
    int sd;
    sd=(data[i]-average)*(data[i]-average);
    sdtotal=sdtotal+sd;
    }

double standarddevation;
standarddevation= sqrt (sdtotal/(size));

//****use formula to find skew;
int skew=3*(average-median)/standarddevation;
//if amount of skew is >-1 or<1, output "badly skewed";
//if amound of skew is <-1 oe >1, output "not badly skewed";

 if (skew>=-1&&skew<=1)
    cout<<"not badly skewed";
 if (skew<-1||skew>1)
    cout<<"badly skewed";
}
int main()
{
skew();

  return 0;
}
well, still having trouble, and havent gotten much help.. heres my latest code. thanks for whoever responds=]

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <cmath>


using namespace std;
//*Determine if the given set of  value creates a skewed graph or not
// Determine if a data set is skewed
void skew ()
{//***set array to proper size;
    int size=10000;
double datapoint;
                        /*input data;
                            ask for how many data entries there are;
                            ask for data entries;*/int counter=0;                   //***set array to proper size;
double* data = new double [size];
                //***input and store data into array;
 while (!cin.eof()) // No Ctrl-Z or Ctrl-D
    {
//int arrayofdata (size);
//***input and store data into array
counter++;
    cin>>datapoint;
    data[counter]=datapoint;
    }


size=counter;
    cout<<"this is the new size"<<size<<endl<<endl;
    for (int i=0; i<size; i++)
    cout<<data [i];
//***order array into ascending order;
//order function
// Step through each element of the array

//***order array into ascending order;for (int i=0; i<size; i++){
for (int nStartIndex = 0; nStartIndex < size; nStartIndex++)
{
    int nlargestIndex = nStartIndex;

    for (int nCurrentIndex = nStartIndex + 1; nCurrentIndex < size; nCurrentIndex++)
    {
        if (data[nCurrentIndex] > data[nlargestIndex])
            nlargestIndex = nCurrentIndex;
    }
    swap(data[nStartIndex], data[nlargestIndex]);
}





  //****use given formula to find mean (average);
 int total=0, average;
for (int b=0; b<size; b++){
    total=total+data[b];}
    average=total/size;


//****use given formula to find median;
float median;
float temp;
if(size%2==0)
median=(data[size/2]+data[size/2-1])/2;
else
median= data[size/2];
//use formula to find the standart deveation
double sdtotal=0;
for (int i=0; i<size; i++){
    int sd;
    sd=(data[i]-average)*(data[i]-average);
    sdtotal=sdtotal+sd;
    }

double standarddevation;
standarddevation= sqrt (sdtotal/(size));

//****use formula to find skew;
int skew=3*(average-median)/standarddevation;
//if amount of skew is >-1 or<1, output "badly skewed";
//if amound of skew is <-1 oe >1, output "not badly skewed";

 if (skew>=-1&&skew<=1)
    cout<<"not badly skewed";
 if (skew<-1||skew>1)
    cout<<"badly skewed";
}
int main()
{
skew();

  return 0;
}


i got it to exit the loop setting up the array using ctrl^z or ctrl^D, but i cant get the size to set right.. any help?
are you trying to resize your array to just be sufficient enough for values that have been read into it? if that is the case you might want to try using vectors.
yes, however i've never been taught vectors.. any help?
Topic archived. No new replies allowed.