issue with array

I am trying to get this gradebook to give me the average/low/high score for three assignments from three different students which i have to get their first/last name, their rank, and major. Everything is working properly except when I try to find the average/low/high score from each assignment it is only doing it for the third assignment and i cant figure out whats wrong with 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
  #include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main()
{
	int intDataArray[3] = { 0 };
	int sumTotalArray = 0;
	int maxScore = 0;
	int minScore = 0;
	int count = 0;

	std::string firstNames[3];
	std::string lastNames[3];
	std::string rank[3];
	std::string major[3];

		for (count = 0; count <= 2; count++)
		{
			std::cout << "Enter student's first name:" << count + 1 << ": ";
			std::cin >> firstNames[count];

			std::cout << "Enter student's last name:" << count + 1 << ": ";
			std::cin >> lastNames[count];

			std::cout << "Enter student's rank:" << count + 1 << ": ";
			std::cin >> rank[count];

			std::cout << "Enter student's major:" << count + 1 << ": ";
			std::cin >> major[count];

			std::cout << "Enter student's assignment score 1:";
			std::cin >> intDataArray[count];


			std::cout << "Enter student's assignment score 2:";
			std::cin >> intDataArray[count];

			std::cout << "Enter student's assignment score 3:";
			std::cin >> intDataArray[count];

			sumTotalArray = sumTotalArray + intDataArray[count];

			if (count == 0)
			{
				maxScore = intDataArray[count];
				minScore = intDataArray[count];
			}
			else
			{
				if (intDataArray[count] > maxScore)
				{
					maxScore = intDataArray[count];
				}
				

				if (intDataArray[count] < minScore)
				{
					minScore = intDataArray[count];
				}
			}

		}

		std::cout << "Array total is: " << sumTotalArray << std::endl;
		std::cout << "The average of the number is: " << sumTotalArray / 3 << std::endl;
		std::cout << "Max score is: " << maxScore << std::endl;
		std::cout << "Min score is: " << minScore << std::endl;

		return 0;

		}

	

Any help would be greatly appreciated!
You are muddling the number of students (3) with the number of assignments (also, unfortunately, 3).
If you look at your loop you put something into the same array element (intDataArray[count]) three times. So, at the end, it will always have the last one ... which is just the mark for assignment 3.
Each student has three assignment grades, which would yield a total of nine integers / array elements. You only have an array of three integers to represent all the grades for all students.
You will need either three arrays with three elements each, a multidimensional array or an array of nine elements.
Last edited on
So (xismn) your saying that I should store the assignment scores for each assignmet number into a different array ex assignment 1 goes to say intDataArray, assignment 2 into intDataArrayx and the third assignment into intDataArrayz ?
"should" - up to you: this is xismn's first suggestion.

His second suggestion (multidimensional array) might ultimately be better and more flexible - in the future, there might be a different number of students and a different number of assignments.

Actually, if all you are doing is finding max/min/average then there is no point in storing the individual data items anyway.
Topic archived. No new replies allowed.