inFile.ignore help?

So I'm working on a project where we input a txt file and create an output for it. My problem is that we are supposed to skip the first line in the file because it is header info and my program keeps skipping the first two lines. Here is my program

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

using namespace std;
int ucost;
int uniformcost();


int main ()
{
int NO;
string firstname, lastname;
string POS;
string grade;
int feet, inches;
int weight;
string home;
int height;
int count;
count=0;
char dash;
double ucost, lcost, tcost;
int sum;
sum=0;

string filename;
ifstream inFile;

cout << "Enter the name of the input file: " ;
cin >> filename;

inFile.open(filename.c_str () );

if (!inFile)
{
cout<<"Cannot Open Input File."<<endl;
cout<< "Program Terminates!"<<endl;
return 1;
}
cout<< filename << " was opened" << endl<<endl;
inFile.ignore (200,'\n');

inFile >> NO >> firstname >> lastname >> POS >> grade >> feet>> dash>> inches >> weight >> home;
getline (inFile, home);
while ( inFile)
{
inFile >> NO >> firstname >> lastname >> POS >> grade >> feet>> dash>> inches >> weight >> home;
getline (inFile, home);

cout<<"Jersey Number: " << NO<< endl;
cout<< "Name: " << firstname << " "<< lastname<<endl;
cout<< "Position: "<< POS<< endl ;
cout<< "Grade Level: "<< grade<< endl;
cout<<"Height: "<< feet << dash<< inches << endl;
cout<< "Weight: "<< weight<<endl ;
cout<< "From: "<< home <<endl<<endl;
count++;




int heightinches;
heightinches= (feet*12) + inches;

if (heightinches<= 72)
{ucost=200;}

else if (weight>260)
{ucost=255;}

else if (72<heightinches<=76)
{ucost=225;}

int lcost;
lcost= (lastname.length ()) * 2;
int ncost;
if (NO<=10)
ncost=5;
else
ncost=10;

int totalcost1;
totalcost1= ucost + lcost+ ncost;
int tuniformcost;

if (grade.length() ==5)
tuniformcost= totalcost1 *2;
else
tuniformcost = totalcost1 *4;


cout<<" Uniform cost is: $"<< ucost<<endl;
cout<< " Cost for letters: $"<<lcost <<endl;
cout<< " Cost for numbers: $"<< ncost<< endl;
cout<< " Total cost for 1 uniform: $"<< totalcost1<<endl;
cout<< "Total Uniform Cost: $"<< tuniformcost<<endl<<endl<<endl;

sum=sum+tuniformcost;

}

cout<<"============================================="<<endl;
cout<<" Team Stats "<<endl;
cout<<"============================================="<<endl;
cout<<endl<<endl;
cout<<"Number of Players: "<< count<<endl;
cout<<"Total Monthly Uniform Cost: "<< sum<<endl;



}



mind you its only about 2/3 done and still needs functions but it all seems to work except its starting on the third line of data instead of the second. I'm pretty sure it has something to do with the inFile.ignore(200. 'n') line but can't find what. Any help would be extremely appreciated.
Please format your code using the [code][/code] tags or the <> button.

Also could you include the output you are getting and the contents of the file?
cotents

NO NAME POS CLASS HEIGHT WEIGHT Hometown/High School/Last College
60 Josh Mann OL SO 6-4 300 Virginia Beach, Va./Ocean Lakes
64 Ricky Segers K/P FR 5-11 185 Glen Allen, Va./Henrico
70 Brandon Carr OL RS_SR 6-2 305 Chesapeake, Va./Western Branch/Fork Union Military Academy
53 Calvert Cook LB FR 6-0 250 Norfolk, Va./Booker T. Washington
51 Michael Colbert DE RS_SR 6-1 230 Fayetteville, N.C./E.E. Smith
22 T.J. Cowart CB RS_JR 5-9 190 Virginia Beach, Va./Ocean Lakes
1 Jakwail Bailey WR SO 5-11 185 Haddonfield, N.J./Paul VI
25 Andre Simmons S JR 6-0 205 Lorton, Va./South County/Vanderbilt
34 Johnel Anderson RB FR 5-8 180 Sicklerville, N.J./Paul VI




I don't know how to copy and paste the output, I'm doing it through remote desktop. I just know it should start with number 60 but instead starts on 64.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;
int ucost;
int uniformcost();


int main ()
{
int NO;
string firstname, lastname;
string POS;
string grade;
int feet, inches;
int weight;
string home;
int height;
int count;
count=0;
char dash;
double ucost, lcost, tcost;
int sum;
sum=0;

string filename;
ifstream inFile;

cout << "Enter the name of the input file: " ;
cin >> filename;

inFile.open(filename.c_str () );

if (!inFile)
{
cout<<"Cannot Open Input File."<<endl;
cout<< "Program Terminates!"<<endl;
return 1;
}
cout<< filename << " was opened" << endl<<endl;
inFile.ignore (200,'\n');

inFile >> NO >> firstname >> lastname >> POS >> grade >> feet>> dash>> inches >> weight >> home;
getline (inFile, home);
while ( inFile)
{
inFile >> NO >> firstname >> lastname >> POS >> grade >> feet>> dash>> inches >> weight >> home;
getline (inFile, home);

cout<<"Jersey Number: " << NO<< endl;
cout<< "Name: " << firstname << " "<< lastname<<endl;
cout<< "Position: "<< POS<< endl ;
cout<< "Grade Level: "<< grade<< endl;
cout<<"Height: "<< feet << dash<< inches << endl;
cout<< "Weight: "<< weight<<endl ;
cout<< "From: "<< home <<endl<<endl;
count++;




int heightinches;
heightinches= (feet*12) + inches;

if (heightinches<= 72)
{ucost=200;}

else if (weight>260)
{ucost=255;}

else if (72<heightinches<=76)
{ucost=225;}

int lcost;
lcost= (lastname.length ()) * 2;
int ncost;
if (NO<=10)
ncost=5;
else
ncost=10;

int totalcost1;
totalcost1= ucost + lcost+ ncost;
int tuniformcost;

if (grade.length() ==5)
tuniformcost= totalcost1 *2;
else
tuniformcost = totalcost1 *4;


cout<<" Uniform cost is: $"<< ucost<<endl;
cout<< " Cost for letters: $"<<lcost <<endl;
cout<< " Cost for numbers: $"<< ncost<< endl;
cout<< " Total cost for 1 uniform: $"<< totalcost1<<endl;
cout<< "Total Uniform Cost: $"<< tuniformcost<<endl<<endl<<endl;

sum=sum+tuniformcost;

}

cout<<"============================================="<<endl;
cout<<" Team Stats "<<endl;
cout<<"============================================="<<endl;
cout<<endl<<endl;
cout<<"Number of Players: "<< count<<endl;
cout<<"Total Monthly Uniform Cost: "<< sum<<endl;



}
Lines 45/46 are reading a line but aren't outputting what was read. You probably don't even need to do that read outside the loop; just let the loop take care of it.
I think I originally put that there to try to help me with a function that I ended up not using and haven't gone back to take it out yet. I'm completely lost with functions:-( but I'm more concerned with the fact that I'm missing the whole first line of data from my output.
That's the problem though. You read in a line of input there but don't output it, so it appears to be missing.
Oooo ok I see what your saying. Would you have any idea how to create some functions from my formulas? I'm supposed to have at least four but every time I try to make one I just end up with error messages.
Have you tried reading the tutorial on this site?
http://cplusplus.com/doc/tutorial/functions/
It covers probably all the stuff you'd need to know to declare/define/call functions yourself.
ok took out that extra line you said but now my output is printing the last line of data twice. The one that starts with 34.
Is there any extra whitespace on the line at the end of the file?
I'm not sure what you mean. The file has 10 lines then the rest of the page is blank.
If there was an extra blank line at the end, it might have caused the loop to attempt to read another line an not get any data.
it just repeats the last line of data before it stops. so while i should have 9 players info to work with it's giving me 10.
So you checked and there is no whitespace or anything on a line after the last person?
Topic archived. No new replies allowed.