Hey everyone! Well I'm sooo close to getting the names to align BUT there is 1 slot that is skipped in the non-smoking section and a few in the smoking section and i can't figure out why. The Data needs to be displayed in a 10 row x 3 column format (first 7 rows being non-smokers and last 3 rows being for smokers). Any help would be greatly appreciated! Thanks!
Here's what I've coded so far. (LINES 39-70 is what I need help with)
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
struct roster
{
string last_name;
string first_name;
char smoking;
int row;
int seat;
};
int main()
{
int x,y;
roster manifest[41];
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 >> manifest[x].last_name;
info >> manifest[x].first_name;
info >> manifest[x].smoking;
info >> manifest[x].row;
info >> manifest[x].seat;
}
info.close(); // finished with the file
cout << "\t\t*******************************************\n"
<< "\t\t* NON-SMOKING SECTION *\n"
<< "\t\t*******************************************\n\n";
for (x = 0, y = 0; x < 41; x++,y++)
{
if(manifest[x].smoking == 'N')
{
cout << "\t" << manifest[x].last_name << " " << manifest[x].first_name << "\t";
if (y > 2) // used to add newline after 3rd name in row
{
cout << endl;
y = 0; // resets the counter back to zero to start over
}
}
}
cout << "\n\n"
<< "\t\t*******************************************\n"
<< "\t\t* SMOKING SECTION *\n"
<< "\t\t*******************************************\n\n";
for (x = 0, y = 0; x < 41; x++,y++)
{
if(manifest[x].smoking == 'S')
{
cout << "\t" << manifest[x].last_name << " " << manifest[x].first_name << "\t";
if (y > 2)
{
cout << endl;
y = 0;
}
}
}
cout << endl;
system("PAUSE");
return 0;
}
Here is what the text file I'm pulling the data from looks like (in case it helps):
SMITH JOHN N 3 2
JOBS STEVEN S 9 3
CAPONE AL N 3 2
JACKSON MICHAEL S 8 1
HUMPHREY H S 8 2
RINEHART JIM N 3 1
EASTMANN KEN N 1 1
WINSTON SALEM S 8 3
SMYTHE SUSAN S 9 1
KENDRICKS AL S 9 2
ALLISON DENNIS S 9 3
GREENBLATT RICHARD S 10 1
DAVIS BOB S 10 3
WOODS BILL S 10 2
BORAX M.T S 9 2
HENRY JOHN N 1 2
STEVASON E N 1 3
WILLIAMS KEN N 2 1
SMITH MARTHA N 2 2
KOCH JOE N 2 3
PACKARD H.P N 3 3
RINEHART JANE N 3 2
SWENSON CECIL N 4 1
CORY TROY N 4 2
BYES NICKOLINE N 4 3
BYES JENNIFER N 5 3
HARRIS JOHN N 5 2
HARRIS JUDY N 5 1
HARTMAN F.G N 6 1
SOUSE D.T N 6 2
JOHNSON MAGIC N 6 3
HAMPTON GEORGE N 7 1
THOMAS LINDA N 7 2
HAYWARD MARK N 7 3
SWIFT TOM N 8 1
DOBBS DR. N 8 2
GOLDEN VINNIE N 8 3
HACKER E N 5 3
RUSSEL STEVE N 5 2
CHAMPION SPARKY N 3 1
INNERMENTS TEX S 8 2