Question on sorting

Can you guys take a look my code below? I am trying to sort the data by netpay ( firstname, lastname, net pay). Included for statements for names in the for statement- sorting net pay. Can not get this to work. Really appreciate any help.

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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
 #include<iostream>
#include<fstream>  
#include <iomanip>  	
	using namespace std; 


	struct person{
           char ms;
           float firstname;
            float lastname;
	      long int id;
	      int    hoursworked;
	      int    overtimehours;
	      int    regularhours;
	      float hourlyrate;
	      float regularpay;
	      float overtimepay;
	      float grosspay;
	      float taxrate;
	      float taxamount;
          float netpay;             };    
int  readalldata( person[ ], const int );           
	void findovertimehours( person[ ], int ); 
	void findovertimepay( person[ ], int ); 
	void findregularhours( person[ ], int );
	void findregularpay( person[ ], int );
	void findgrosspay( person[ ], int );
	void findtaxrate( person[ ], int );
	void findtaxamount( person[ ], int );
	void findnetpay( person[ ], int );

	
	void sortbypointers(person[ ], int);
	void printalldata( person[ ], int );
	
	       int main( ){
              
      const int MAXSIZE = 100;   	
      int n;             
      person employee[ MAXSIZE ];        
      n = readalldata( employee, MAXSIZE ); 
	      findovertimehours( employee, n );
	      findovertimepay( employee, n );
	      findregularhours( employee, n  );
      findregularpay( employee, n );
      findgrosspay( employee, n );
	      findtaxrate( employee, n );    
      findtaxamount( employee, n );
      findnetpay( employee, n );
      sortbypointers(employee,n);
      printalldata( employee, n );     
         
	      return 0; 
}

 int readalldata( person emp[ ], int n ){
     ifstream fin( "payrolldavid.in" );
      n = 0;
     while( fin >> emp[ n ].firstname >> emp[ n ].lastname >> emp[ n ].hoursworked >> emp[ n ].hourlyrate ){   
          n++;   }
     fin.close( );
      return n;
 }
 void findovertimehours( person emp[ ], int n ){
     for( int i = 0 ; i < n ; i++){
           if( emp[ i ].hoursworked > 40 )
                emp[ i ].overtimehours = emp[ i ].hoursworked - 40;
          else
               emp[ i ].overtimehours = 0;
     }
 }
 void findovertimepay( person emp[ ], int n ){
      for( int i = 0 ; i < n ; i++){
          emp[ i ].overtimepay = emp[ i ].overtimehours * emp[ i ].hourlyrate * 1.5;
      }
 }
 void findregularhours( person emp[ ], int n ){
     for( int i = 0 ; i < n ; i++){
           if( emp[ i ].hoursworked > 40 ) emp[ i ].regularhours = 40;
         else   emp[ i ].regularhours = emp[ i ].hoursworked;
     }
}
 void findregularpay( person emp[ ], int n ){
      for( int i = 0 ; i < n ; i++ ){
          emp[ i ].regularpay = emp[ i ].regularhours * emp[ i ].hourlyrate;
     }
}
 void findgrosspay( person emp[ ], int n ){
     for( int i = 0 ; i < n ; i++){
          emp[ i ].grosspay = emp[ i ].regularpay + emp[ i ].overtimepay;   
      }
}
 void findtaxrate( person emp[ ], int n ){
    for( int i = 0 ; i < n ; i++){
          if( emp[ i ].grosspay > 1000.00 ) emp[ i ].taxrate = 0.30; 
          else if( emp[ i ].grosspay >800.00 ) emp[ i ].taxrate = 0.20;
          else if( emp[ i ].grosspay > 500.00 ) emp[ i ].taxrate = 0.10;
          else emp[ i ].taxrate = 0.0;
          
             if (emp[ i ].ms=='S') emp[ i ].taxrate=(emp[ i ].taxrate+.05);
                            else if (emp[ i ].ms=='s') emp[ i ].taxrate=(emp[ i ].taxrate+.05);
                            else if (emp[ i ].ms=='H' && emp[ i ].grosspay > 500.00 ) emp[ i ].taxrate=(emp[ i ].taxrate-.05);
                            else if (emp[ i ].ms=='h' && emp[ i ].grosspay > 500.00 ) emp[ i ].taxrate=(emp[ i ].taxrate-.05);
                            else emp[ i ].taxrate=(emp[ i ].taxrate*1);
                          
                            
      }
}
 void findtaxamount( person emp[ ], int n ){
     for( int i = 0 ; i < n ; i++){
           emp[ i ].taxamount = emp[ i ].grosspay * emp[ i ].taxrate;
      }
 }
void findnetpay( person emp[ ], int n ){
      for( int i = 0 ; i < n ; i++){
          emp[ i ].netpay = emp[ i ].grosspay - emp[ i ].taxamount;
      }
 }
 
 
void sortbypointers(person emp[ ], int n){ 
  
     int i,j;
     float *p[n];
     float *q[n];
     float *k[n];
     double temp;
     int sortedflag=0;
 
for(i=0;i<n;i++) p[i]=&emp[ i ].netpay; 
for(i=0;i<n;i++) q[i]=&emp[ i ].firstname; 
for(i=0;i<n;i++) k[i]=&emp[ i ].lastname; 

  while (!sortedflag){
   sortedflag=1;
   
   for(j=0;j<n-1;j++ ){  
      if (*p[j]>*p[j+1]){ 
        temp=*p[j];
     *p[j]=*p[j+1];
     *p[j+1]=temp;
     sortedflag=0;    } // if
  
       

      if (*q[j]>*q[j+1]){ 
        temp=*q[j];
     *q[j]=*q[j+1];
     *q[j+1]=temp;
     sortedflag=0;    }// if
    
     
      if (*k[j]>*k[j+1]){ 
        temp=*k[j];
     *k[j]=*k[j+1];
     *k[j+1]=temp;
     sortedflag=0;    } // if
     
     } // for
     }  // while
     
                      }     //void
                       
              

                      
                      
void printalldata( person emp[ ], int n ){
     cout << " First Name" << "\t" << "Last Name" << "\t" << "Net " << endl;
     for( int i = 0 ; i < n; i++){
          cout << " " << emp[ i ].firstname << "\t " << emp[ i ].lastname
                  << "\t" << emp[ i ].netpay << "\t " << endl;
    }
  system ("pause");}
 
Well... what are we supposed to be looking for? What does the code actually do in place of what it should do?

-Albatross
sorry should have been more clear. The output produces the labels, no data at all. this is the input file ( first name, last name, hours, rate):

Alison Cameron 43 100.00
Peter Barcia 40 120.75
Mike Johnson 35 110.50
Remy Thirteen 52 20.25
Lisa Cuddy 34 45.00

I am looking to sort the netpays, with the appropriate first/last name
Can you guys please give me some pointers? I believe the error is in the firstname/lastname logic. I just cant seem to get it to work
Topic archived. No new replies allowed.