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
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');
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.
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.
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.
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.