Sentinals and I/O redirection.

I am doing a homework assignment for my class and I keep getting stuck. I have been staring at it for hours. This is the code that I have:

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*************************************************************************/
/*                          LAB ASSIGNMENT #2                            */
/* Program that generates a weekly payroll in a company of 10 employees  */
/* using a sentinel value                                                */
/*      Programmer: Marisa Ver Hage                                      */
/*      Class:      CS 2400                                              */
/*      Due Date:   Feb. 14, 2013                                        */
/*************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
#include  "employeeinfo.h"
#define DUMMYVALUE -99.0
int main()
{
   cout.setf(ios :: fixed);
   cout.setf(ios :: showpoint);

   /*-------- variables ----------*/
   double totalTax = 0, totalPay = 0; // running total for gross pay and tax
   int hoursTotal, count;           // total number of hours employee
                                  //worked in a week
   employeeInfo employee;       // to hold the information about the employee

        /*------------ read ID + sentinal -------------*/

        cin >> employee.id;
        if (employee.id != DUMMYVALUE)
        {
        cin >> employee.id;
           /*--------- read employee information -----------*/
           cin >> employee.last >> employee.first
              >> employee.birthDate.month >> employee.birthDate.day
              >> employee.birthDate.year >> employee.dateOfHire.month
              >> employee.dateOfHire.day >> employee.dateOfHire.year
              >> employee.payRate;

           /*---------- hours total computation --------*/

           hoursTotal = 0;
           count = 0;
           while (count < 5)
           {     
              cin >> employee.hours;
              if (employee.hours != DUMMYVALUE)
              {
                 hoursTotal += employee.hours;  
                 cin >> employee.hours;
              }
              count ++; 
           }

           /*---------- compute gross pay  ----------*/

           employee.grossPay = employee.payRate * hoursTotal;
           totalPay += employee.grossPay;

           /*--------- compute tax ---------*/

           if (employee.grossPay >= 1000 )
                employee.tax = employee.grossPay * 0.20;
           else if (employee.grossPay >= 800)
                employee.tax = employee.grossPay * 0.18;
           else
                employee.tax = employee.grossPay * 0.15;

           totalTax += employee.tax;

           /*--------- compute net pay ----------*/

           employee.netPay = employee.grossPay - employee.tax;

           /*--------- output employee's information ----------*/

           cout << setprecision(2);
           cout << endl << employee.last + ", " + employee.first;
           cout << endl << "ID:\t" << fixed << setw(21) << employee.id;
           cout << endl << "DOB:\t" << fixed << setw(17) 
                << employee.birthDate.month << "/" 
                << employee.birthDate.day 
                << "/" << employee.birthDate.year;
           cout << endl << "DOH:\t" << fixed << setw(17) 
                << employee.dateOfHire.month << "/" 
                << employee.dateOfHire.day  << "/" 
                << employee.dateOfHire.year;

           cout << endl;

           cout << endl << "Pay Rate:\t" << fixed << setw(9) << "$"
                << employee.payRate;
           cout << endl << "Hours:\t" << fixed <<  setw(18) 
                << hoursTotal;
           cout << endl << "Gross Pay:\t" << fixed << setw(9) << "$"
                << employee.grossPay;
           cout << endl << "Tax:\t" << fixed << setw(17) << "$"
                << employee.tax;
           cout << endl << "Net Pay:\t" << fixed << setw(9) << "$"
                << employee.netPay;

           cout << endl << endl;

        }

   /*------ end loop ---------*/

   cout << endl << "Total Gross Pay:\t$" << totalPay;
   cout << endl << "Total Gross Tax:\t$" << totalTax;
   cout << endl;
   return 0;

}



Here is the employeeinfo.h file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*------------------------ employeeinfo.h --------------------------*/

#include <string>
using namespace std;
#include  "date.h"

/*----------- Structure to represent an employees information -----------*/
struct  employeeInfo
{
        string first, last;      // employees first name and last name.
        int id, hours;           // employees ID number & hours worked.
        double payRate, grossPay,
               netPay, tax;          // employees pay rate, etc. 
        date birthDate, dateOfHire;    // employees date of birth. 
};


and here is the input file

1
2
58243 Doe John 10 25 1981 6 15 2005 8.75 7 4 7 5 8
-99.0


The program has an infinite loop and I am new to Unix. I just need some suggestions.

This is the homework objective:

To process the weekly payroll in a company of one or more employees. Each employee has worked 5 days in the week and the number of hours of work per day is a number from 1 to 8.

1. The information about a date consists of the month, the day, and the year. Define a structure type Date to represent this information.

2. The information about an employee consists of his first name, last name, ID number, date of birth, date hired, the pay rate, and the number of hours worked during a week. Define a structure type EmployeeInfo to represent this information.

3. For this assignment, you will use the header file lab2.h that you have created in Lab2.

4. Create and save in your CS240 directory the file lab3.input that contains the information about the employees: use one line of input for each employee.

5. 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 as follows:
a. The gross pay is the pay rate times the total number of hours worked.
b. The tax deduction is computed as follows:
If gross pay is greater than or equal to 1000, 20% of the gross pay;
If 800 <= gross pay < 1000, 18% of gross pay
If 600 <= gross pay < 800, 15% of gross pay
otherwise, 10 % of the gross pay.
c. The net pay is the gross pay minus the tax deduction.
d. Also compute the total gross pay and total tax deduction of the company and print it.

6. Compile, link and execute your program on the UNIX computer using I/O redirection.


If your confusion is with I/O redirection, that is not a problem. All you have to do is when you compile/run your program, on the command line do this:

$ prog_name.exe < input_file_name

This "<" symbol is the most common way of redirecting input, there is also pipelines which are more useful for combining and running multiple programs which depend on each other's output at once.

However, if your problem is with the code, you would have to explain what is not working.

I don't understand why you are doing the same thing twice:
line 27 and 30 / line 44 and 48. Also, how is date.h declared?
Topic archived. No new replies allowed.