Function issues in a payroll program.
| tdigdug (36) | |||
Using Dev C++. The Program works with one minor problem. The fname and the lname comes out blank. here is the code.
Does anyone see my mistake. | |||
| justlearning56 (7) | |||
| Not sure if I'm looking at this right but in the line : while(fin>>fname[i]>>lname[i]>>id[n]>>hw[n]>>hr[n]>>ms[n]) n++; Don't you want fname[n]>>lname[n] ? | |||
| tdigdug (36) | |||
| fname and lname I did switch back to [n], I switch it to i to see if it would correct the missing names but it didn't work as well. | |||
| LostStudent (27) | |||
| This may not be all of the problem, but, you are missing the # in your line: include<iostream>. It should read #include<iostream> | |||
| tdigdug (36) | |||
| Iforgot to copy the #, sorry. | |||
| LostStudent (27) | |||
No sorries.......here is my code that worked:
| |||
| guestgulkan (252) | |||
| I don't think that code worked... are you sure that's the right stuff?? | |||
| tdigdug (36) | |||
| I wonder if the # of functions has something to do with it? hmmmm | |||
| justlearning56 (7) | |||
| I'm not sure how to pass char arrays to a function but that appears to be where your trouble is. If you take the code for outputall and put it into main in place of the function call your program seems to output correctly. At least with only one data item in the test file I made. | |||
| LostStudent (27) | |||
| Yes, the code worked perfectly. I am using Dev C++ 4.9.9.2 as the compiler. | |||
| tdigdug (36) | |||
| I'm using dev C++ as well 4.9.9.2. Lost are you talking about my orig or with the cout in the main? | |||
| guestgulkan (252) | |||
OK - in the one you say worked I was questioning the following lines:
Once those lines are commented out then the file read will work like you say. I have also noticed that in the code you said worked you are reading the file as firstname, lastname,ID, status,hoursworked, hourlypay , but in the first code you posted you are reading the file lines as firstname, lastname, id, hoursworked, hourlypay, status have you done something with the file layout design?? | |||
| tdigdug (36) | |||
| Sorry Gulkan. But you are looking at two different codes with similar subjects. | |||
| LostStudent (27) | |||
| Gulkan.......It did compile......this is the output: DR. EBRAHIMI'S PAYROLL INSTITUTE FIRST LAST ID STAT HW HR OTH OTP REGP GROSS TAX NET ===== ===== ==== ==== === === === === ===== ===== ==== ===== John Smith 2222 M 50 15 10 2250 600 2850 0.3 $1995 Jane Dow 3333 M 45 10 5 375 400 775 0.1 $697.5 Holly Sorrell 4444 M 40 25 0 0 1000 1000 0.2 $800 Mary Adams 5555 S 30 15 0 0 600 600 0.15 $510 Kyle Mustard 6661 M 42 10 2 60 400 460 0 $460 Press any key to continue . . . It looks better on the print screen...but, that's the output. | |||
| tdigdug (36) | |||
| Is that mine or is that loststudents program? | |||
| tdigdug (36) | |||
| Thanks Lost, your program gave some ideas to fix my error. It works just fine now. The void function(void) I was the key. I take it your in the same class, so if you want to email through the class, last name is Rigdon. | |||
This topic is archived - New replies not allowed.
