![]() |
| | #1 |
| Registered User Join Date: Apr 2009
Posts: 8
| 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! |
| blueshift1980 is offline | |
| | #2 |
| Registered User Join Date: Apr 2009
Posts: 8
| Doh! Somehow forget one of the variables. |
| blueshift1980 is offline | |
| | #3 |
| Registered User Join Date: Jan 2002 Location: Northern Virginia/Washington DC Metropolitan Area
Posts: 2,787
| Yep, the loop evaluates to false the first time through since you're attempting to read in an integer ssn where there is a char in the file... so you never enter the loop body.
__________________ On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. --Charles Babbage, 1792-1871 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 |
| hk_mp5kpdw is offline | |
![]() |
| Tags |
| arrays, datafile, input file |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help for my output array | qwertysingh | C Programming | 1 | 02-17-2009 03:08 PM |
| Modify an single passed array element | swgh | C Programming | 3 | 08-04-2007 08:58 AM |
| Merge sort please | vasanth | C Programming | 2 | 11-09-2003 12:09 PM |
| Struct *** initialization | Saravanan | C Programming | 20 | 10-09-2003 12:04 PM |
| Array Program | emmx | C Programming | 3 | 08-31-2003 12:44 AM |