lost with my c++ code

I have updated my code to what i have now. I am no longer stuck in a loop, but my problem now is nothing is being send to the output file.



#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main ()
{
ofstream outputFile;
ifstream inputFile;
char inFile[30];
char outFile[30];
char Player[21];
int Pawn, Knight, Bishop, Rook, Queen, Total;

// Output report headings

outputFile << "Chess Player Report" << endl << endl;
outputFile << "Player" << setw(20) << " "
<< "Pawns" << setw(5) << " "
<< "Knights" << setw(5) << " "
<< "Bishops" << setw(5) << " "
<< "Rooks" << setw(5) << " "
<< "Queens" << setw(5) << " "
<< "Total" << endl << endl;

// Main processing loop - obtain data from input file, compute total,
// and direct results to the output file

do
{
cout << "What is the input file: ";
cin >> inFile;
inputFile >> ws;
inputFile.open(inFile);
cout << "What is the output file: ";
cin >> outFile;
outputFile.open(output);
inputFile >> Pawn;
inputFile >> Knight;
inputFile >> Bishop;
inputFile >> Rook;
inputFile >> Queen;
inputFile >> ws;
Total = Pawn * 1 + Knight * 3 + Bishop * 3 + Rook * 5 + Queen * 9;
inputFile >> Total;

outputFile << left << setw(20) << Player
<< right << setw(9) << Pawn
<< right << setw(11) << Knight
<< right << setw(12) << Bishop
<< right << setw(11) << Rook
<< right << setw(11) << Queen
<< right << setw(11) << Total << endl;

}
while (!inputFile.eof());
inputFile.close();
return 0;
}
Last edited on
Do you have an example of the input file?
@fish1709

Well, I see you have
1
2
3
4
5
cout << "What is the input file: ";
cin >> inFile;
inputFile.open(inFile);
cout << "What is the output file: ";
cin >> outFile;
located INSIDE your do/while loop. So you will be be asked for a name of input file each time the EOF is not reached, and it's probably starting at the top of the file each time through since the open file is run in each pass. Move those out of the do/while and see if you see an improvement
Last edited on
@jay6390 an example of the input file would be
Robert Smith
4 2 1 2 1
Jane Doe
3 1 1 2 1


@whitenite1
I understand what your saying but as to where i should move those commands to i am lost. I tried moving it out but my program stopped doing anything at all, and that is probably due to my error of not knowing where to move them to.
Topic archived. No new replies allowed.