Join 137,261 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,510 people online right now. Registration is fast and FREE... Join Now!
Hi everyone. I'm a n00bie both to the site and to C++ programming.
I've been working on this programming assignment this past week and I'm just stumped. Probably something simple and stupid that I missed since I tend to do that and this past week was rediculously busy (taking 5 classes this semester)
Anyway, here's the contents of the "payroll.txt" file accessed in the following program:
QUOTE
John Smith#10.45 40 15 Jane Doe#12.50 45 15 Harry Morgan#20.00 40 20 Carmen Martinez#25.00 35 25 Jacintha Washington#50.85 60 35
And here's what I have as far as code goes. I'm sure my math for the processPay function is wrong. And I'm also sure something else is screwed up since it only seems to output 1 line.
void reportDescription() { cout << "This program calculates paychecks for each employee. "<< endl << "A text file will be created outside of the program with the information: "<< endl << "name, rate of pay, number of hours worked, and tax percentage to be deducted." << endl << endl << "The program will create a report in columnar format showing the employee "<< endl << "name, hourly rate, number of hours worked, tax rate, gross pay, and net pay. "<< endl << endl << "After all employees are processed, totals will be displayed total gross amount "<< endl << "and total net pay." << endl << endl << endl; }
I copied the text from the command line output. Let me see if it'll post as it looks on the screen:
CODE
This program calculates paychecks for each employee. A text file will be created outside of the program with the information: name, rate of pay, number of hours worked, and tax percentage to be deducted.
The program will create a report in columnar format showing the employee name, hourly rate, number of hours worked, tax rate, gross pay, and net pay.
After all employees are processed, totals will be displayed total gross amount and total net pay.
Payroll Report Employee Hourly Hours Tax Gross Net Name Rate Worked Rate Amount Amount
50.85 60.00 35.00 323958709722612380000000000000 0000000000000000000000000000000000.003051.00 Totals3147027465876806800000000000000000000000000000000000000000000000.00-925596 31349317830000000000000000000000000000000000000000000000.00 Press any key to continue . . .
That's basically what it looks like. It doesn't print any of the employee names and only looks like it prints the last line of data from the file. Also, my math is obviously messed up somewhere. lol
I already had that set up in one of the functions, but I added it to the other one that I thought could use it just now.
Didn't seem to help.
I think I have a looping problem somewhere (at least as part of the problem) because it seems like only the last line of the payroll.txt file prints to the screen.
Figured out the looping problems and all that, but still need help with the math in the processPay function.
Should the output be?
CODE
This program calculates paychecks for each employee. A text file will be created outside of the program with the information: name, rate of pay, number of hours worked, and tax percentage to be deducted.
The program will create a report in columnar format showing the employee name, hourly rate, number of hours worked, tax rate, gross pay, and net pay.
After all employees are processed, totals will be displayed total gross amount and total net pay.
Payroll Report Employee Hourly Hours Tax Gross Net Name Rate Worked Rate Amount Amount
John Smith 10.45 40.00 15.00 355.30 418.00 Jane Doe 12.50 45.00 15.00 478.13 562.50 Harry Morgan 20.00 40.00 20.00 640.00 800.00 Carmen Martinez 25.00 35.00 25.00 656.25 875.00 Jacintha Washington 50.85 60.00 35.00 1983.15 3051.00 Totals 4112.83 5706.50
void reportDescription() { cout << "This program calculates paychecks for each employee. "<< endl << "A text file will be created outside of the program with the information: "<< endl << "name, rate of pay, number of hours worked, and tax percentage to be deducted." << endl << endl << "The program will create a report in columnar format showing the employee "<< endl << "name, hourly rate, number of hours worked, tax rate, gross pay, and net pay. "<< endl << endl << "After all employees are processed, totals will be displayed total gross amount "<< endl << "and total net pay." << endl << endl << endl; }
cout << left << setw(5) << "Totals" << right << setw(10) << totalGross << setw(10) << totalNet << endl;
}
Remember when declaring a local variable (inside {}) such as double grossPayTotal=0; // ** zero these totals double netPayTotal=0; its value is by default undetermined; make such you initialise such variables.
This post has been edited by horace: 7 Nov, 2006 - 10:53 PM