keep getting infinite loop output

Write a program that reads the information about the employees in a loop (you must also use another loop to read an employee’s number of hours and compute their sum) and computes their gross pay and net pay. The dummy ID number -99 is used to end the input data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  #include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "EmployeeInfo.h"
#define DUMMYVALUE -99.0
int main()
{
EmployeeInfo employee;
double grosspay, tax, netpay, totalgp=0, totaltax=0, totalhours=0, count=0; 
cin  >>  employee.id;
while(employee.id != DUMMYVALUE)
{ 
	cin >> employee.firstname  >>  employee.lastname
	>>employee.birthday.month
	>>employee.birthday.day
	>>employee.birthday.year
	>>employee.datehired.month
	>>employee.datehired.day
	>>employee.datehired.year
	>>employee.payrate;

while(count < 5)
{
		totalhours+=employee.hours;
		cin >> employee.hours;
		count++;
}


grosspay = totalhours*employee.payrate;
if(grosspay>= 1000)
	tax = .20*grosspay;
else if(grosspay>=800)
	tax = .18*grosspay;
else if(grosspay>=600)
	tax = .15*grosspay;
else
	tax = .10*grosspay;
netpay = grosspay - tax;
totalgp+= grosspay;
totaltax+= tax;
cout << "Name: "  << employee.lastname + "," + employee.firstname << endl;
       cout <<"ID : "<<employee.id << endl;
       
       cout << "DOB: "<<employee.birthday.month << "/"
		     <<employee.birthday.day << "/"
		     <<employee.birthday.year << endl;
       cout << "BOH: "<<employee.datehired.month << "/"
		      <<employee.datehired.day << "/"
		      <<employee.datehired.year << endl;
       cout <<"Hours:  "<<totalhours << endl;
       cout <<"Pay Rate: $"<<employee.payrate << endl;
       cout <<"Gross Pay: $"<<grosspay << endl; 
       cout <<"Tax: $"<<tax << endl;
       cout <<"Netpay: $"<<netpay << endl;
       cout <<"Total gross pay: $"<<totalgp<<endl;
       cout << "Total tax deduction: $" <<totaltax<<endl;
       cout << endl << endl;  
}
cout<< "Total grosspay =$"<<totalgp<<endl;
cout<<"Total tax=$"<<totaltax<<endl;
return 0;
}
Your while loop runs from line 13 to line 68.
First time through you prompt for employee.id at line 11.
Once you enter the while loop, you never input employee.id again, therefore you loop will never terminate.
so then where should the "cin >> employee.id" statement be placed ?
bump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <iomanip>
#include <string>

// #define DUMMYVALUE -99.0

struct EmployeeInfo
{
    int id ;
    // ...
};

int main()
{
    const int DUMMYVALUE = -99 ;

    EmployeeInfo employee;
    while( std::cin >> employee.id && employee.id != DUMMYVALUE )
    {
        // read in rest of employee info
        // validate
        // calculate stuff
        // print result
    }
}
can't put a cin statement in a while loop argument, duh!
can't put a cin statement in a while loop argument

You most certainly can. The result of a cin >> operation is an istream reference which has a bool operator. You can test an istream reference in any statement that accepts a bool expression.
Topic archived. No new replies allowed.