Test array to see if it is empty.

Pages: 12
I did all your steps and still getting errors.

Input: The letter H.
Output: The output is a count of HOW MANY numbers have been input so far. This could be as small as zero.

Input: The letter M.
Output: The output is the MEDIAN of all the input numbers read so far. The median is a number that has no more than half of the input numbers below it and no more than half the input numbers above it. For example, if there have been five input numbers 2, 2, 3, 6 and 5, then the median is 3 since two of the five numbers are below 3 and two of the five numbers are above 3. Notice that if there has been an even number of inputs (such as 2, 3, 6, 5) then there may be several choices for the median (in this example, the median could be either 3 or 5). In this case, it does not matter whether the output is the 3 or the 5. If there has not yet been any input numbers, then the program should print the word "ERROR" instead of the median.

Input: The letter Q.
Output: The program outputs the word "END" and then stops.
Your fixed code :
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
#include <iostream>
#include <algorithm>

using namespace std;

int main() {

	int aArray[99];
	double sum;
	double avg;
	double maxValue;
	double n,p;

	int mode;

	int i = 0;
	int j;

	char choice;
	bool done = false;

	do {
		cout << "\nWelcome the the Stats array\n Choices are\n N = numbers\n S = sum of all\n A = average of all\n B = biggest of all\n F = most frequent of all \n H = how many numbers \n M = median of all \n q = quit\n ";
		cout << "Select a choice:  ";
		cin >> choice;

		switch (choice)
		{
		case 'N':
		case 'n':

                    cout << "\nEnter Number: ";
                    cin >> aArray[i];
                    while(aArray[i] < 1 || aArray[i] > 99)
                    {
                        cout << "Please enter a number greater than 0 and less than 99"<<endl;
                        cout << "Enter Number: ";
                        cin >> aArray[i];
                    }
                    i++;
			break;
		case 'S':
		case 's':
			sum = 0;
			for (j = 0; j < i; j++) {
				sum = sum + aArray[j];
			}
			cout << endl;
			cout <<"\n The sum of array is: " << sum << endl;
			cout << endl;
			break;
        case 'A':
        case 'a':
        sum = 0;
        avg = 0;
        if(i == 0)
             {
               cout << "ERROR" << endl;
                break;
               }
            else
               {
                for (j = 0; j < i; j++)
                {
                sum = sum + aArray[j];
                avg = (sum/i);
                }
               }

            cout << endl;
            cout <<"\n The average of array is: " << avg << endl;
            cout << endl;
            break;
        case 'B':
		case 'b':
        maxValue = 0;
        if(i == 0)
             {
               cout << "ERROR" << endl;
                break;
               }
               else
               {
                for (j = 0; j < i; j++)
                    if(aArray[j] > maxValue)
                        {
                            maxValue = aArray[j];
                        }
               }

            cout << endl;
			cout <<"\n The biggest value of array is: " << maxValue << endl;
			cout << endl;
			break;
        case 'F':
        case 'f':
        mode = aArray[0];
        for(j = 1; j < i; j++)
        if(std::count(&aArray[0], &aArray[i], aArray[j]) >  std::count(&aArray[0], &aArray[i], mode)) mode = aArray[j];
        cout <<"\n The most frequent value of array is: " << mode << endl;
        cout << endl;
        break;
        case 'H':
        case 'h':
        while (aArray[j]!= '\0')
        {
                    n++;
                    // aArray[n] = aArray[j];
        }
        cout << "There are "<<n-1 << " elements in the array.";
        cout << endl;
        break;
        case 'Q':
		case 'q':
        done = true;
        break;
		default:
			cout << "\nInvalid choice End of Program";
			break;


}

	} while (!done);
}
Thanks
I am now having trouble finding the median:

Here is what I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
case 'M':
        case 'm':
        int j;
        int num;

        if(i == 0)
             {
               cout << "ERROR" << endl;
                break;
               }
               if(num % 2 != 0){//
              int j = ((num+1)/2)-1;
                    cout << "The median is " << aArray[j] << endl;
                }
                else{// then it's even! :)
                    cout << "The median is "<< aArray[(num/2)-1] << " and " << aArray[num/2] << endl;
                }
            }
Topic archived. No new replies allowed.
Pages: 12