I am working with a problem that pulls information from an input file. Here is the .cpp file:
The payroll.txt file contains the following data:Code:#include <iostream> #include <iomanip> #include <fstream> using namespace std; main(){ char firstName[5][12]; char lastName[5][15]; int ssn[9]; int hoursWorked[5]; double grossPay[5],netPay[5],hourlyRate[5],otHours[5],otPay[5],taxRate[5], regularPay[5],taxAmount[5]; int counter=0; int i; ifstream fin("payroll.txt"); if(!fin){ cout<<"Could not read input file. \n"; return 1; } while(fin>>firstName[counter]>>lastName[counter]>>ssn[counter]>>hoursWorked[counter]>>hourlyRate[counter]>>otHours[counter]>>otPay[counter]>>regularPay[counter]>>grossPay[counter]>>taxAmount[counter]>>netPay[counter]) { cout<<grossPay[counter]<<endl; //cout<<lastName[counter]; cout<<"Counter is: "<<counter; counter++; cout<<"Now: "<<counter; } } // end main
SampleFirst SampleLast M 555555555 40 35 0 0 1400 1400 140 1260
John Smith M 77777777 50 10 10 100 500 600 30 570
Oddly enough, if I take out the braces around the while loop, it will output the counter values. The statement to check if the file is opened always fires correctly (i'm assuming, since it does not throw an error).
Thanks for the help!