Data Processing using file input and parallel arrays

We are given a file with student id numbers, student name, course code, course credits and course grade. the students are repeated based on the number of classes they take. What we are supposed to do is make a grade report. I'm not finished but from what I have it runs, but it will only show information from the first student. I'm not sure how to fix it! And it's due in an hour!
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>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	const int SIZE=30;
	string name[SIZE], id[SIZE], code[SIZE], idnumber ;
	int credits[SIZE], numStudents;
	char grade[SIZE];
	int cred=0;

	ifstream inFile;
	inFile.open("input.txt");
	if(!inFile)
		cout<<"Could Not Open File!"<<endl;
	else
	{
		numStudents=0;
		inFile>>id[numStudents];
		while(!inFile.eof())
		{
			inFile.ignore();
			getline(inFile, name[numStudents]);
			inFile>>code[numStudents];
			inFile>>credits[numStudents];
			inFile>>grade[numStudents];
			numStudents++;
			inFile>>id[numStudents];
		}
	}
			int i=0;
			cout<<"Enter Student ID Number (EXIT to quit): ";
			cin>>idnumber;
			while(idnumber != "EXIT")
			{
				if (idnumber==id[i])
				{
					cout<<"Student Name: "<<name[i]<<endl;
					cout<<"Student ID Number: "<<id[i]<<endl<<endl;
					cout<<"Course Code\tCourse Credits\tCourse Grade"<<endl;
					cout<<"============================================"<<endl;
					
					for (i=0; idnumber==id[i]; i++)
					{
						cout<<code[i]<<"\t\t"<<credits[i]<<"\t\t"<<grade[i]<<endl<<endl;
						cred+=credits[i];
					}
					
					cout<<"Total Semester Course Credits Completed: "<<cred<<endl;
					cout<<"Semester GPA: "<<endl;
					cred=0;
				}
				
			
				cout<<"Enter Student ID Number (EXIT to quit): ";
				cin>>idnumber;
	
			}
	
	inFile.close();
	



	return 0;
}
line 35 you have set i=0 then use it as an index to your array. So on line 40 your always checking idnumber == id[0] That looks like where you might have your hang up
I added an i++ at the end and it didn't work...
When it starts its index[0] then gets incrimented in the for loop on line 47. So I cant realy tell what i is at the end of the loop without debugging.

loop through the array of ids to check if one exists to your input then return the your incrementer.

1
2
3
4
5
6
7
8
9
10
11
12
13
for(i=0; i<SIZE; i++)
{
     if(idnumber == id[i])
     {
     x = i;
     }
}


if (idnumber==id[x])
{
    cout<<"Student Name: "<<name[x]<<endl;
    cout<<"Student ID Number: "<<id[x]<<endl<<endl;


Just an example. That way it looks for the ID then sets x to the index that you need.
Last edited on
Topic archived. No new replies allowed.