array help

I was hoping someone could give me a hand with this. I am very much a beginner, and trying to learn this has been a challenge. I need to fix my last void function so that it reads the array into an if else if statements and counts all the data in the data file into which is seen, and then I output the information directly to the console right from the function. However, as you can see I am getting errors. In QSummery(inValues[]), I am getting an error, inValues[] is undefined, but I don't know what else to call, all I need for the function is to receive the array of values and count them. Besides that, I have one other error that I cannot figure out, for for( int i = 1;) where it says it expected and expression. Beyond that, I would appreciate any advice on the logic of my function. If anyone can help, I would much appreciate it.

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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# include <iostream>
# include <fstream>
# include <cmath>
using namespace std;

const int MAX_ARRAY = 500;

void getData(ifstream& inFile, int inValues[], int& size);
double getAverage(int inValues[], int dataSize); 
void MaxMin(int theData[], int dataSize, int&Max, int&Min);
double StandardDev(int inValues[], int numElems, double Ave);
void QSummery(int inValues[]);


int main()
{
    ifstream fileIn;                
    
    int theData[MAX_ARRAY];     // Array for data storage
    int numElems;               // Actual number of values in array 
                                // (1 more than largest index)
	int Max, Min;				// decleration for maximum and minimum values
	double Ave;
	double SDev;

    fileIn.open("pgm5data.txt"); // Open file
    
    if (fileIn.fail() )         // Test for file existence
    {
      cout <<  "Problem opening file";
      exit(-1);
    }
    
    // Read file and count values in array
    getData(fileIn,theData,numElems);
    
   // Determine and write average; test first for non-empty data file   
    if (numElems > 0)
	{
	   Ave = getAverage(theData,numElems);
       cout << "Average Test Score: " << Ave << endl << endl;
	}
     else
       cout << "ERROR:  No data processed" << endl << endl;

 MaxMin(theData, numElems, Max, Min);

	//return max and min value
	if (numElems > 0)
		cout << "Max: " << Max << " Min: " << Min << endl << endl;
	else 
		cout << "ERROR: No data processed" << endl << endl;

SDev = StandardDev(theData, numElems, Ave);

	//returns the standard deviation
	cout << "The standard deviation for the data set is: " << SDev << endl;

	QSummery(inValues[]);

    // Close file
    fileIn.close();    

	system("pause");
   
    return 0;                
} 

// This function reads integers from a file and stores the values in
// an array.  It returns the loaded array and the number of elements 
// in the array
void getData(ifstream& inFile, int inValues[], int& numVals)
{
    int i = 0;
    inFile >> inValues[i];                
    while (!inFile.eof() && i < MAX_ARRAY)    // Test for end of file and array    
    {
       i++;        
       inFile >> inValues[i];
    }            
    numVals = i;
}

// This function receives an array of integers, calculates the average
// of the array values, and returns it.
double getAverage(int inValues[], int dataSize)
{
    double sum = 0.0;
    
    for (int i = 0; i < dataSize; i++)
       sum = sum + inValues[i];    
       
    return sum / dataSize; 
}

//This function will calculate and return the maximum and minimum value
void MaxMin(int theData[], int dataSize, int&Max, int&Min)
{
     Max = theData[0];       // start with max = first element

     for(int i = 1; i<dataSize; i++)
     {
          if(theData[i] > Max)
                Max = theData[i];
     }
	  Min = theData[0];       // start with min = first element

     for(int i = 1; i<dataSize; i++)
     {
          if(theData[i] < Min)
                Min = theData[i];
     }
}
 // This function will calculate the standard deviation  of the numbers in the data set
 double StandardDev(int inValues[], int numElems, double Ave)
 {
	 double StandardDev;
	 double sum = 0;
	 double temp;
	 for (int i = 0; i < numElems-1; i++)
	 {
		 temp = inValues[i] - Ave;
		 sum = sum + pow(temp, 2);
	 }
	 StandardDev = sqrt(sum/ (numElems-1));

	 return StandardDev;
 
 }

 void QSummery(int inValues[])
 {
	 double quartile4, quartile3, quartile2, quartile1;
	 for( int i = 1;)
	 if (inValues[i] > 74)
		 quartile4++;
	 else if (inValues[i] > 49)
		 quartile3++;
	 else if (inValues[i] > 24)
		 quartile2++;
	 else 
		 quartile1++;

	 cout << "The Quartile 4, scores between 75 - 100 are as follows: " << quartile4 << endl;
	 cout << "The Quartile 3, scores between 50 - 74 are as follows: " << quartile3 << endl;
	 cout << "The Quartile 2, scores between 25 - 49 are as follows: " << quartile2 << endl;
	 cout << "The final Quartile, 1, scores between 0 - 24 are as follows: " << quartile1 << endl;
 }
What is it you want to pass to QSummery? If it is theData you write QSummery(theData);

A for loop
1
2
3
4
for (a;b;c)
{
	d;
};
can be rewritten using a while loop:
1
2
3
4
5
6
a;
while (b)
{
	d;
	c;
};

a is an init-statement. In your code you have written int i = 1 here.
b is the loop condition, an expression that evaluates to true as long as the loop should continue.
c is a statement that is executed at the end of every loop iteration.
d is just whatever statement, or lines of code inside the loop.
Last edited on
not exactly, I need to use inValues to get the array data for use in my void function to use in the loop. But it says its an undeclared identifier. On top of that I get a syntax error in my for loop and I feel like inValues is the problem.
Last edited on
Believe it or not, that's because inValues is an undeclared identifier in main.

Naming a function parameter inValues doesn't mean inValues is defined in main. It also doesn't mean the function has to be called with a variable named inValues. Look at StandardDev and how you call it.

As for your "for" problems. Take another gander at Peter87's post and figure out what your loop is missing. Look at your other for loops. How are they different?
Topic archived. No new replies allowed.