Help needed for a Payroll Program Please!

Hello, I am having problems with a payroll problem. It only computes every other employee, and I cannot get the overtime hours to total properly. I have to use the instructor provided template, and the stringstream for this program. Can someone please take a look and help me? The file I have to bring in is below it.

Thanks,
spyder1
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* Program Name:   Payroll3.cpp

   Description: 

   Name: 			Class No.: 2441
   Date:  02/25/08	Dev-C++
*/
//********************************** Includes
#include <cfloat>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cctype>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
#include <ctime>
#include <conio.h>
#include <windows.h>
#include <sstream>

#define cls system("cls")
#define frz system("pause");
#define yl  system("color 0e");

using namespace std;

//********************************** Type definitions

//********************************** Function Prototypes
ifstream infile("f:\\paydata3.txt");
//********************************** Main Function


int main()
{
	time_t t;
	time(&t);
	yl;
    int i, C, M, count, total ; 
    string  office, depend, hrrate, wkhrs, otwkhr;
	stringstream strval1, strval2, strval3, strval4; 
	double gross=0, net, fed, fica, city, dues, totgross, totfed, totfica, 
           tothours,  sswkhrs, sshrrate, ssdepend, totovthrs, ssotwkhrs;	
    count = 0;
    total = 0;
    totovthrs=0;
    string text = "";
    string first = "";
    string last = "";
    string empun = "";
    string empid = "";
    

    cout << " Payroll3. cpp " << ctime(&t) << endl << endl;
    cout << fixed << showpoint << setprecision(2);
    cout << "Emp Number " <<"First Name " << "Last Name      " << "Hours  " 
         << "Rate  " << "Overtime " << "Gross  " << "Fed Tax " << "FICA " 
         << "City Tax " << "Union Dues " << "Net Pay " << endl;
      
 if  (!infile)
       {
        cout << "An error has occurred while opening the file!" << endl;
        frz;
        }//end for infile
   
   while (!infile.eof())
   { 
         getline(infile, text);
         infile.ignore(80,'\n');
         count++;
               
          first = text.substr(15,10);
          last = text.substr(0,15);
          office = text.substr(25,1);
          empun = text.substr(26,1);
          empid = text.substr(27,5);
          wkhrs = text.substr(32,4);
          hrrate = text.substr(36,5);
          depend = text.substr(41,2);
          otwkhr = text.substr(43,4);
          
            
            strval1 << wkhrs;
            strval1 >> sswkhrs;
            strval2 << hrrate;
            strval2 >> sshrrate;
            strval4 << otwkhr;
            strval4 >> ssotwkhrs; 
            cout << ssotwkhrs << endl;
            gross = ((sswkhrs * sshrrate) + ((1.5 * sshrrate) * ssotwkhrs));
            
            strval3 << depend;
            strval3 >> ssdepend;
            fed = (( gross - (17 * ssdepend))*.1834);
          
         

          if (office=="C"){
            city = (gross * .04);
          }
              else{
                  city = (gross * 0.00);
                  }


          
          if (empun=="M"){
            dues = (gross * .0473);}
                else{
                 dues = (gross * 0.00);}
      
            
            
            fica = (gross * .07650);
            net = (gross -(fed + fica + city + dues));    
            totgross = totgross + gross;
            totfed = totfed + fed;
            totfica = totfica + fica;
            tothours = tothours + sswkhrs;
            totovthrs += ssotwkhrs;    

  
    cout << setw(8) << empid << setw(15) << first << setw(15) << last << setw(6) 
         << wkhrs << setw(8) << hrrate << setw(8)<< otwkhr << setw(8) << gross
         << setw(8) << fed << setw(6) << fica << setw(10) << city << setw(10) 
         << dues << setw(8) << net << endl << endl;

         
  
    }//end while     
    cout << fixed << showpoint << setprecision(2);
    cout << left << setw(33) <<"Number of employees processed =  " 
         << count << endl;
    cout << left << setw(33) << "Total Gross Pay =  " 
         <<totgross << endl;
    cout << left << setw(33) <<"Total Federal Tax =  " 
         <<totfed << endl;
    cout << left << setw(33) << "Total Hours Worked =  " 
         << tothours << endl;
    cout << left << setw(33) << "Total Overtime Hours Worked =  " 
         << totovthrs << endl;
    frz;
    
     infile.close();
    // print.close();  

return 0;
} // end of main function


//********************************** Function Definitions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Schanz         Hannelore SX1234540.009.551000.0
Liffer         Umfritz   CM2345638.508.670301.5
Ajahb          Fyndmee   CX3456739.606.830203.9
Zyzz           Abba      CX4567840.310.910200.5
Goodgrayed     Ineeda    SM5678938.713.520202.0
Bath           Uneeda    CM6789039.311.110102.5
Strongbreeze   Ifelta    CM7890139.607.930300.0
Anapple        Iyate     SX8901239.905.950000.0
Kulate         Cal       SX9012340.007.870104.0
Isemtee        Mytank    CM0123440.514.880712.5
Lihd           Flippa    CM1123440.112.220410.3
Lyfe           Getta     CM2234540.206.750309.4
Franzipanni    Gwoppo    SM3345637.805.920205.3
Sanchez        Fillipina CX4456738.311.220106.1
Regulurr       Ear       SX5567839.410.050300.0
Enstance       Hap       SM6678940.409.250204.4
Lawreeyat      Backa     CM7789040.009.310202.2
Doothis        Ugonna    CM8890139.013.250203.3
Rupowch        Kanga     CM9901238.615.960612.8
Lewser         Sheesa    SX1112344.312.940308.1
Bustid         Mikars    SM2223440.308.880502.3
Mylegg         Letgo     CM3334548.913.380811.1
Stee           Iyamthur  CX4445644.408.880101.7
Last edited on
Topic archived. No new replies allowed.