F
foker
I have this problem where I have 2 text files, one with student name,
id#, # of courses and course #, the second file has course name and
course number. I want to make a multidimensional array that takes the
student id into one portion and the course id into the other. This is
my code:
include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
int i = 0;
int student_info[500][25];
string first_name, last_name, course_name;
ifstream courses_file;
courses_file.open("courses.txt");
if (courses_file.fail())
{
cerr << "Could not open courses.txt" << endl;
exit(1);
}
ifstream students_file;
students_file.open("students.txt");
if (students_file.fail())
{
cerr << "Could not open students.txt" << endl;
exit(1);
}
int index = 0;
while(students_file >> first_name >> last_name >>
student_info[index][25])
{
index++;
while(courses_file >> course_name >> student_info[500])
{
i++;
}
}
}
When I print out my array I get a bunch of garbage. One of problems is
I am taking in first_name, last_name, student id number in the array
but after that theres a list of course id's the student is taking so
like a random number. I can't get past the student id in the first line
of the file. It prints out junk. Can someone help me understand what my
problem is here and how to fix it?
id#, # of courses and course #, the second file has course name and
course number. I want to make a multidimensional array that takes the
student id into one portion and the course id into the other. This is
my code:
include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
int i = 0;
int student_info[500][25];
string first_name, last_name, course_name;
ifstream courses_file;
courses_file.open("courses.txt");
if (courses_file.fail())
{
cerr << "Could not open courses.txt" << endl;
exit(1);
}
ifstream students_file;
students_file.open("students.txt");
if (students_file.fail())
{
cerr << "Could not open students.txt" << endl;
exit(1);
}
int index = 0;
while(students_file >> first_name >> last_name >>
student_info[index][25])
{
index++;
while(courses_file >> course_name >> student_info[500])
{
i++;
}
}
}
When I print out my array I get a bunch of garbage. One of problems is
I am taking in first_name, last_name, student id number in the array
but after that theres a list of course id's the student is taking so
like a random number. I can't get past the student id in the first line
of the file. It prints out junk. Can someone help me understand what my
problem is here and how to fix it?