File input/output help

confused on where I went wrong, plz help.


#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

using namespace std;

int main()
{

ifstream inputFile;
ofstream outputFile1, outputFile2, outputFile3, outputFile4;

inputFile.open("cisdegree.txt");

outputFile1.open("appmajors.txt");
outputFile2.open("netmajors.txt");
outputFile3.open("progmajors.txt");
outputFile4.open("webmajors.txt");

outputFile1.setf(ios::fixed);
outputFile1.setf(ios::showpoint);
outputFile1.precision(2);

outputFile2.setf(ios::fixed);
outputFile2.setf(ios::showpoint);
outputFile2.precision(2);

outputFile3.setf(ios::fixed);
outputFile3.setf(ios::showpoint);
outputFile3.precision(2);

outputFile4.setf(ios::fixed);
outputFile4.setf(ios::showpoint);
outputFile4.precision(2);


if (inputFile.fail())
{
cout << " Error Opening File" << endl;
exit(1);
}

String LastName, FirstName;
Char MiddleInitial, MajorCode;

int StuNum;
double GradePointAvg;

Int count = 0;
While(!inputFile.eof())
{

inputFile >> StudNum >> LastName >> FirstName >> MiddleInitial >> GradePointAvg >> MajorCode;

if (MajorCode == ‘A’)
outputFile1 << StudNum << LastName << FirstName << MiddleInitial << GradePointAvg;

if (MajorCode == ‘N’)
outputFile1 << StudNum << LastName << FirstName << MiddleInitial << GradePointAvg;

if (MajorCode == ‘P’)
outputFile1 << StudNum << LastName << FirstName << MiddleInitial << GradePointAvg;

if (MajorCode == ‘W’)
outputFile1 << StudNum << LastName << FirstName << MiddleInitial << GradePointAvg;

count++

}

double StuNum, GradePointAvg;

string LastName, FirstName;

//string FirstName;

char MiddleInitial, MajorCode;

inputFile >> StuNum >> LastName >> MiddleInitial >> LastName >> GradePointAvg >> MajorCode;

inputFile.close();

outputFile1.close();

outputFile2.close();

outputFile3.close();

outputFile4.close();


return 0;

}
This won't compile.

Int count = 0;
This line is bad.

1
2
String LastName, FirstName;
Char MiddleInitial, MajorCode;

Seriously, this isn't English composition class. English sentences begin with a capital letter. Lines of C++ code follow different rules and "String" is different to "string".

count++
This line is bad.


When your compiler complains, read the error messages and look at the code around where it points you at.
Last edited on
thanks, I found my mistakes
Topic archived. No new replies allowed.