Problem with 2d Array function passing

I seem to be having trouble with my code fellas an assignment i have been working on for the past couple days has been driving me crazy when i compile this it just sits idle and does nothing. So apparently i've done something wrong and it doesn't like. Could you be so kind to let me know what is going on. Thanks

I am reading from a file taking the names of students they are all in a format like so:
Johnston 65 56 45 65 78
10 rows of this i have to take the name and store it into a string and take the scores and put it in a 2d array and then average the scores then print it out in a different outfile i've made it far enough to read it.. (or so i think) but when i compile this my compiler doesn't like it at all.

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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;
const int ROW = 5;
const int COL= 10;

void readData(string n[], int s[ROW][COL], ifstream& in);
//void calculateAverage(int s[ROW][COL], ofstream& out, double aver[]);

int main(){

	ifstream inFile;
	ofstream outFile;
	
	
	string name[9];
	int score[ROW][COL];
	double average[10];

	readData(name, score, inFile);


}

void readData(string n[], int s[ROW][COL], ifstream& in){
	int i =0;
	in.open("studentscores.txt");

if(!in){
cout << "Cannot find file!" << endl;
exit(1);
}

while(!in.eof()){
	in >> n[i] >> s[i][0] >> s[i][1] >> s[i][2] >> s[i][3] >> s[i][4];

++i;

}
	in.close();
}

//void calculateAverage(int s[ROW][COL], ofstream& out, double aver[]){

//	out.open("StudentScoreRESULTS.txt");

	
//} 
Could you show the errors you got?
i didn't get any errors when i compiled but the cmd screen just froze and i had to ctrl + alt + del to end it

i've edited the code a little bit i did have cout statements to try to print the array to see if it was reading it correctly but it keeps freezing on the cmd and can't get any further than that
Last edited on
As I have understood your input file has 10 records. But you defined the array of names as having size only of nine elements

string name[9];

and defined array score as having only 5 rows and 10 columns. And at the same time you are triyng to read in only 5 columns in each row.

I think the problem is that you do not understand yourself what you are doing.
Last edited on
Ah i seen the string issue, thanks for catching that that is a little problem i do a lot because i always add 0 into the mess thinking it was 10, thanks for the catch. So it is me being logically idiotic, thanks

the text file looks like this:

Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63

so in the while loop i take the name put it into the names array, then take the first score put it into the first element into the 2d array then stretch it across that row then switch to the next and so on.
Last edited on
I got it now Thanks for pointing out that logical issue i appreciate it
So what values shall have ROW and COL?
Topic archived. No new replies allowed.