My code wont extract the file can someone please help?

This should be my input file
John Smith A
Sue Jones C
Ray Adams B
And this should be my output file
Smith, John, Zone A, $75.00
Jones, Sue, Zone C, $30.00
Adams, Ray, Zone B, $55.00
Total Charges: $160.00



#include<iostream>
#include<cstring>
#include<cmath>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include<ctime>
#include<string>

using namespace std;
const double ZONE_A = 75.00;
const double ZONE_B = 55.00;
const double ZONE_C = 30.00;
const int SEATS = 100;


struct TicketHolder
{
string holderFName;
string holderLName;
char zone;
double charge;
};
int loadData(TicketHolder audience[]);
void addCharge(TicketHolder audience[], int numPeople);
double totalCharge(TicketHolder audience[], int numPeople);
void outputData(TicketHolder audience[], int numPeople, double someTotal);

int main()
{
int numPeople = 0;
double someCharge = 0;
TicketHolder audience[SEATS];
numPeople = loadData(audience);
addCharge(audience, numPeople);

someCharge = totalCharge(audience, numPeople);

outputData(audience, numPeople, someCharge);


system("pause");
return 0;
}

int loadData(TicketHolder audience[])
{
TicketHolder inputStruct;
string inputFile;

ifstream inFile;
int i = 0;
cout << "Please enter the file name of the audience names and their zones " << endl;
cin >> inputFile;
inFile.open(inputFile);
while (inFile.peek() != EOF)
{
inFile >> inputStruct.holderFName;
cin.ignore();
inFile >> inputStruct.holderLName;
cin.ignore();
inFile >> inputStruct.zone;
cin.ignore();
audience[i] = inputStruct;
i++;
if (i == 99)
{
cout << " Out of Seats " << endl;
break;
}
}
inFile.close();
return i;
}

void addCharge(TicketHolder audience[], int numPeople)
{
//TicketHolder audience;
for (int i = 0; i < numPeople; i++)
{
if (audience[i].zone == 'A')
audience[i].charge = ZONE_A;
else if (audience[i].zone == 'B')
audience[i].charge = ZONE_B;
else if (audience[i].zone == 'C')
audience[i].charge = ZONE_C;
}
}
double totalCharge(TicketHolder audience[], int numPeople)
{
double total = 0;
for (int i = 0; i < numPeople; i++)
{
total += audience[i].charge;
}
return total;
}
void outputData(TicketHolder audience[], int numPeople, double someTotal)
{
TicketHolder output;
ofstream outFile;
string outputFile;
cout << " What do you want the output file to be called? " << endl;
cin >> outputFile;
outFile.open(outputFile);
for (int i = 0; i < numPeople; i++)
{
outFile << output.holderLName;
outFile << output.holderFName;
outFile << output.zone;
outFile << someTotal;
}

}
Last edited on
What file won't open?

How do you know the file won't open, since you never check to insure that the files opened properly?
It just showed up as a blank file its not extracting the information
What "just showed up as a blank file"?

You need to check the streams to insure that the files opened correctly. Just assuming that files open correctly is one of the biggest problems when dealing with files.

Also please fix the code tags in your first post, as presented your code is very difficult to read.

It is opening but it is reading the file as blank
How do you know it is opening? Where are you checking that the files opened correctly?
I showed you the problem in your other post. Why two posts?
http://www.cplusplus.com/forum/beginner/192246/
Topic archived. No new replies allowed.