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
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;
}
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.