write a program that reads info about the employee, the number of hours are read in a loop and their sum is stored in the structure as the number of hours worked during the week, computes gross pay, tax deduction, netpay and total grosspay and tax deduction of the company.
My program goes thru a never ending loop, does anyone know why ?
Header:
struct Date
{
int month;
int day;
int year;
};
struct EmployeeInfo
{
int id;
string firstname;
string lastname;
Date birthday;
Date datehired;
float payrate;
int hours;
};
I count 11 input 'cin's, but your input has more values. You should put a breakpoint on the line after cin, run in debug mode and see what the values of your employee object are. You'll quickly be able to see the value of employee.hours, and you'll know why it doesn't stop!
He means that line 13 reads 11 values from the input, but the input file has 16 values on each line. So the first time through the loop it reads the 11 values, which means that employee.hours does NOT get set to -99 because it hasn't read that yet. The next time through the loop it reads the 12th value of the first line into the employee ID, the 13th value into the first name etc. When it gets to the last name on the second line, the read fails and you're hosed from there on.
Here are the first two records output. Notice that the second record is all messed up.
$ ./foo < foo.in | head -40
Name: Doe,John
ID : 58243
DOB: 10/25/1981
BOH: 6/15/2005
Hours: 7
Pay Rate: $7
Gross Pay: $61.25
Tax: $6.125
Netpay: $55.125
Total gross pay: $61.25
Total tax deduction: $6.125
Name: 5,7
ID : 4
DOB: 8/-99/51423
BOH: 0/15/2005
Hours: 14
Pay Rate: $7
Gross Pay: $122.5
Tax: $12.25
Netpay: $110.25
Total gross pay: $183.75
Total tax deduction: $18.375
He meant to run the program in a debugger. Do you know what a debugger is? It's a way to run a program and tell the computer to stop at specific places. Then you can examine the variables etc. He's saying to stop execution at line 14 by putting a "breakpoint" there. That tells the debugger to stop the program at that location. Then you should examine the contents of the employee variable.
bump adding a breakpoint to line 14 didn't help and i don't know how to debug... Anyone know what's wrong with the sourcefile can anyone see the reason for the non ending loop ?
Maybe its becuase, You tell it while(employee.hours != -99)
You tell it, as long as employee.hours is not equal to 99, run this loop.
So once you enter the loop. employee.hours never changes. employee.hours never becomes -99. And the loop will run forever until employee.hours = 99;
it was part of our assignment "number of hours are read in a loop and their sum is stored in the structure as the number of hours worked during the week"