Histogram/loop issues

Trying to take my gradeScale array, which holds all the grades the user enters, and create a histogram that would tally up how many as, bs, cs, ds, and fs there are. This would be counted in the bin array. However, my loop isnt working.

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
#include <iostream>

using namespace std;

void inputArray(int*, int*);
void calculate(int*, int*, int*, int*);
//void display();

int main() {
	int studentGrades[30];
	int gradeScale[101];
	int bin[5];
	int values = 0;
	
	inputArray(studentGrades, &values);
	calculate(studentGrades, gradeScale, bin, &values);

	cout << "grade = " << gradeScale[10] << endl;
	cout << "grade = " << gradeScale[50] << endl;
	cout << "fs = " << bin[0] << endl;
	cout << "ds = " << bin[1] << endl;
	cout << "cs = " << bin[2] << endl;
	cout << "bs = " << bin[3] << endl;
	cout << "as = " << bin[4] << endl;

	system ("pause");
	return 0;
}

void inputArray(int *studentGrades, int *values) {
	
	cout << "Enter test score for student " << *values + 1 << " (or -1 to quit): ";
	cin >> studentGrades[*values];

	while (studentGrades[*values] != -1) {
		++(*values);
		cout << "Enter test score for student " << *values + 1 << " (or -1 to quit): ";
		cin >> studentGrades[*values];
	}
}

void calculate(int *studentGrades, int *gradeScale, int *bin, int *values) {
	int ticker = 0;

	for (int index = 0; index < 101; index++)
		gradeScale[index] = 0;

	for (int index = 0; index < *values; index++) {
		int score = studentGrades[index];
		gradeScale[score] += 1;
	}

	for (int index = 0; index < 5; index++)
		bin[index] = 0;

	for (int index = 0; index < *gradeScale; index++) {
		if (gradeScale[index] <= 59) 
			bin[0] += 1;
		else if (gradeScale[index]>= 60 && gradeScale[index] <=69) 
				bin[1] += 1;
		else if (gradeScale[index]>= 70 && gradeScale[index] <=79) 
				bin[2] += 1;
			else if (gradeScale[index]>= 80 && gradeScale[index] <=89) 
				bin[3] += 1;
			else if (gradeScale[index]>= 90 && gradeScale[index] <=100) 
				bin[4] += 1;
		}
}

//void display() 
which loop isn't working exactly? You have more than one loop
The last one(last group of if statements.). Its supposed to use the bin array to count how many of each letter grade there are for a histogram.
Anyone?
I'd say that on line 56 index < *gradeScale is wrong (supposed to be index < *values?)

Further more gradeScale seems to contain the amount of the percentage not the actual percentage itself. So I'd guess that you should use studentGrades instead?
Topic archived. No new replies allowed.