Hey so ive been trying to fix this for quite a while now and I cant figure out what went wrong. I made the code to store the data from the files into the structure. When I did that and ran it I was able to input a file name, but after inputting it the screen didn't change, leaving the filename as the only output. Any suggestions on what went wrong, thank you for any help!
Here is the input text:
Smith Jr., Joe
111-22-3333
3
Physics I
A 5
English 1A
B 4
Chemistry 101
F 5
Here is the code:
#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct Student {
string fullName;
string idNumber;
double gpa;
int unit;
char grade;
string title;
};
bool openFile(ifstream & fin);
void Read_info(Student list[], ifstream & fin);
int main()
{
Student empList[10];
ifstream fin;
if (openFile(fin)) {
Read_info(empList, fin);
cout << "2";
}
return 0;
}
bool openFile(ifstream& fin) {
string fileName;
getline(cin, fileName);
fin.open(fileName);
if (fin.fail()) {
cout << "Bad file.\n";
return false;
}
if (fin.peek() == EOF) {
cout << "No data to process.\n";
return false;
}
return true;
}
void Read_info(Student list[], ifstream& fin) {
getline(fin, list[0].fullName);
getline(fin, list[0].idNumber);
while (!fin.eof()) {
for (int i = 0; i < 10; ++i) {
getline(fin, list[i].title);
fin >> list[i].grade >> list[i].unit;
fin.ignore(10, '\n');
}
}
}