Okay... apparently I'm not making sense when writing my reply's. So I'll do this. I've written a code here:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void outputStudents(string students);
void outputTeachers(string teachers);
void outputStaff(string staff);
int main()
{
string students, teachers, staff;
outputStudents(students);
outputTeachers(teachers);
outputStaff(staff);
return 0;
}
void outputStudents(string students)
{
string firstname;
string lastname;
string street;
string city;
string state;
int housenumber, zipcode, anumber;
ifstream fin;
ofstream fout;
fin.open("program6.txt");
fout.open("student.txt");
if(fin.fail())
{
cerr << "Unable to open input file, this is outputstudents\n";
exit(2);
}
if(fout.fail())
{
cerr << "Unable to open output file\n";
exit(3);
}
cout << "Your up to the while loop at students\n";
while (fin >> anumber >> firstname >> lastname >> housenumber >> street >> city >> state >> zipcode)
{
if (anumber==0)
{
fout << firstname << setw(10) << lastname << setw(10) << housenumber << setw(10) << street << setw(10) << city << setw(10) << state << setw(10) << zipcode << endl;
}
}
fin.close();
fout.close();
return;
}
void outputTeachers(string teachers)
{
string firstname;
string lastname;
string street;
string city;
string state;
int housenumber, zipcode, anumber;
ifstream fin;
ofstream fout;
fin.open("program6.txt");
fout.open("teacher.txt");
if(fin.fail())
{
cerr << "Unable to open input file\n";
exit(2);
}
if(fout.fail())
{
cerr << "Unable to open output file\n";
exit(3);
}
cout << "Your up to the while loop at teacers\n";
while(fin >> anumber >> firstname >> lastname >> housenumber >> street >> city >> state >> zipcode)
{
if (anumber==1)
{
fout << firstname << setw(10) << lastname << setw(10) << housenumber << setw(10) << street << setw(10) << city << setw(10) << state << setw(10) << zipcode << endl;
}
}
cout << "The while loop at teachers is working\n";
fin.close();
fout.close();
return;
}
void outputStaff(string staff)
{
string firstname;
string lastname;
string street;
string city;
string state;
int housenumber, zipcode, anumber;
ifstream fin;
ofstream fout;
fin.open("program6.txt");
fout.open("staff.txt");
if(fin.fail())
{
cerr << "Unable to open input file\n";
exit(2);
}
if(fout.fail())
{
cerr << "Unable to open output file\n";
exit(3);
}
cout << "The while loop at staff starts\n";
while(fin >> anumber >> firstname >> lastname >> housenumber >> street >> city >> state >> zipcode)
{
if (anumber==2)
{
fout << firstname << setw(10) << lastname << setw(10) << housenumber << setw(10) << street << setw(10) << city << setw(10) << state << setw(10) << zipcode << endl;
}
}
fin.close();
fout.close();
return;
}
THIS CODE WORKS.
As you can see, the above code works. It was written, step-by-step. I know that in order to make a working program, you write it, step-by-step. Writing it "step-by-step" isn't the problem. If it was, I wouldn't have said I had written it, "step-by-step", in my last post.
Now, what was wrong with the LAST code, the one I wrote in the first post, was that "getInput", was not working. That, and where to put "enum", was the problem. My writing a code, step-by-step, WASN'T the problem. I never said it was. Nor has it been in my writing.
Now, what I need to do, is change the working code you see in this post, so that it uses "enum", a struct (the one I've written in the first post), and a "function" (that is, a code OUTSIDE of "int main") that can be called into another function.
Telling me to "test it after each line", is getting redundant. I know how to debug, I don't know how to write a function that will open an input stream, and then call said function into another function. Nor did I know how to use an "enum", in fact I'm still hazy on it. How, HOW, do you use an when calling data from an input file? Note, I'm using the enum and the struct with an input file, to send data to an output file.
If were still stuck on the "well you need to write it step-by-step" phase, then I guess I'm just not typing in proper English and should wing this thing.