Hello Everyone! So I have an assignment to create a program to read in data from text file. I managed to get that part, but I'm having trouble with two areas.
1. Having the names read from the display read into a 10x3 format (10 rows, 3 colums/seats.)
Expected output:
Capone AL Eastman Ken Henry John
Stevenson E Williams Ken Smith Martha
Etc...
I can't seem to write a for loops that will go to the nextline after the 3rd name without the program running on endlessly.
My output:
Capone Al
Eastman Ken
Henry John
Stevenson E
Etc...
Here's what I have so far (I've bolded the area I need help with):
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string last_name[41];
string first_name[41];
char smoking[41];
int row[41];
int seat[41];
int x;
int y;
char choice;
while((choice != 'Q') && (choice != 'q'))
{
ifstream info; // ifstream variable declaration
// opens text file where data is stored
info.open("ffmanifest.txt");
// for loop to read in data from text file
for (x = 0; x < 41; x++)
{
info >> last_name[x];
info >> first_name[x];
info >> smoking[x];
info >> row[x];
info >> seat[x];
}
info.close(); // finished with the file
cout << "\t\t*** WELCOME TO THE FAST FLIGHT AIRLINES MENU! ***\n\n"
<< "Please select from one of the following options:\n\n"
<< "\ta) View Standard List\n"
<< "\tb) Book New Flight\n"
<< "\tq) Quit\n\n"
<< "\tYour Selection: ___\b\b";
cin >> choice;
switch(choice)
{
case 'A':
case 'a': system("CLS");
cout << endl;
cout << "\t\t*******************************************\n"
<< "\t\t* NON-SMOKING SECTION *\n"
<< "\t\t*******************************************\n\n";
for (x = 0; x < 41; x++)
{
if (smoking[x] == 'N' || smoking[x] == 'n')
{
cout << "\t" << last_name[x] << " " << first_name[x] << endl;
}
}
cout << endl;
system("PAUSE");
system("CLS");
break;
case 'B':
case 'b': char fName[20];
char lName[20];
char smoker;
int seat;
int row;
system("CLS");
cout << "\nEnter Passenger's First Name: ";
cin >> fName;
cout << "Enter Passenger's Last Name: ";
cin >> lName;
cout << "(S)moking or (N)on-Smoking?: ";
cin >> smoker;
cout << "Preferred Seat: ";
cin >> seat;
cout << "Preferred Row: ";
cin >> row;
cout << "\n\nHere is your Fast Flight Information:\n"
<< lName << " " << fName << "\t" << smoker
<< "\t" << seat << "\t" << row << "\n\n";
system("PAUSE");
system("CLS");
break;
case 'Q':
case 'q': cout << endl << "GOODBYE! =)\n\n";
//system("PAUSE");
break;
default: cout << endl << "\"" << choice << "\""
<< " is not a valid choice, please choose "
<< "from one of the options shown.\n\n";
system("PAUSE");
system("CLS");
}
}
//system("PAUSE");
return 0;
}