Problem calling sort function

I am having trouble calling the sort function in the main block. Can you guys give me some feedback?

I recieve a " no matching function for call to `payroll::sortdata(char[14], double&, double&, double&, int&)" error but I dk how to solve it.

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
void payroll:: sortdata( string lastname[] ,double overtimepay[],double taxamount[],  double netpay[], int n ) {
    int i,j; 
    string *alastname[n]; 
    double *aovertimepay[n]; 
    double *ataxamount[n];
    double *anetpay[n];
    double *temp, *tempb, *tempc; 
    string *tempa; 
    int sorted = 0; 

      for( i = 0; i < n; i++ ){
         alastname[i] = lastname + i; 
         aovertimepay[i] = overtimepay + i;
         ataxamount[i] = taxamount +i;
         anetpay[i] = netpay + i; } //for
    
 while (!sorted){
         sorted = 1;
   
   for( j = 0; j < n - 1; j++ ){  
      if ( *anetpay[j] > *anetpay[j+1] ){ 

         temp = anetpay[j];
         anetpay[j] = anetpay[j+1];
         anetpay[j+1] = temp;
         
         tempa = alastname[j];
         alastname[j] = alastname[j+1];
         alastname[j+1] = tempa;  
         
         tempb = aovertimepay[j];
         aovertimepay[j] = aovertimepay[j+1];
         aovertimepay[j+1] = tempb; 
         
         tempc = ataxamount[j];
         ataxamount[j] = ataxamount[j+1];
         ataxamount[j+1] = tempc; sorted = 0;
          
              }//if
         }//for
 }//while
}//sort


.
.
.
.
.

 employee[i]->sortdata(alastname,aovertimepay, ataxamount,anetpay, n);
assuming that you call this:
 
employee[i]->sortdata(alastname,aovertimepay, ataxamount,anetpay, n);

in main, you should verify that the variables you used satisfy you function definition.
My guess would be that the variable alastname is not of the type of string lastname[]
Thanks. I amended it to void payroll::sortdata( char lastname[] ,double overtimepay[],double taxamount[], double netpay[] ) and [code] employee[i]->sortdata(lastname,overtimepay, taxamount,netpay); [/code[] but it still syas I am wrong. any ideas why?
1. what's the new error?
2. this is your original error, right?
no matching function for call to `payroll::sortdata(char[14], double&, double&, double&, int&)

and this is the function declaration:
sortdata( string lastname[] ,double overtimepay[],double taxamount[], double netpay[], int n )

-the 'hint' I gave was there's something wrong in the way you call your function i.e:
employee[i]->sortdata(alastname,aovertimepay, ataxamount,anetpay, n);
while the example I gave was for the variable "alastname", the error might extend to other variables you used, just check whether they're the correct type :)

p/s C/C++ do have built-in sort and swap functions, look it up.
p/p/s ...and there are containers and algorithms, too ;)
Yes i recieve the same error with my adjustments.

With this declaration void payroll::sortdata( char lastname[] ,double overtimepay[],double taxamount[], double netpay[] ) I thought was the correct way to set up the function. And using this employee[i]->sortdata(lastname,overtimepay, taxamount,netpay); to call the function, I still dk where my error is
Show a bit more of the code around the function call. Specifically the variables you are passing as parameters.
Sure. Please see the below.

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
int main() {
    payroll *employee[6], *report;
    char alastname[14],lastname[14], ams, apaystatus;
    int aemployeeid,n, i=0;

    double ahoursworked, ayearlysalary, ahourlyrate, minnp, maxnp, ataxamount,  anetpay, aovertimepay, taxamount,  netpay, overtimepay;

    report->printheaders();
    
    ifstream fin;
    fin.open("2142011.in");

    while (fin>>alastname>>aemployeeid>>ams>>apaystatus>>ahoursworked>>ahourlyrate>>ayearlysalary) {
           if (apaystatus == 's') {
           
              employee[i] = new salaried();
              employee[i]->settingthevariables(alastname, aemployeeid, ams, apaystatus, ahoursworked, ahourlyrate, ayearlysalary, ataxamount,  anetpay, aovertimepay);
              employee[i]->findgrosspay(); }
           if (apaystatus == 'h') {
              employee[i] = new hourly();
              employee[i]->settingthevariables(alastname, aemployeeid, ams, apaystatus, ahoursworked, ahourlyrate, ayearlysalary, ataxamount,  anetpay, aovertimepay);
              employee[i]->findgrosspay();}
             employee[i]->findtaxamount();
             employee[i]->findnetpay();
             employee[i]->sortdata(lastname,overtimepay, taxamount,netpay); 
       
        
           minnp = employee[i]->minnet(minnp, i);
           maxnp = employee[i]->maxnet(maxnp, i);
       
           employee[i]->printdata();
           i++;
     }
      




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
void payroll::sortdata( char lastname[] ,double overtimepay[],double taxamount[],  double netpay[] ) {
    int i,j,n; 
    char *alastname[n]; 
    double *aovertimepay[n]; 
    double *ataxamount[n];
    double *anetpay[n];
    double *temp, *tempb, *tempc; 
    char *tempa; 
    int sorted = 0; 

      for( i = 0; i < n; i++ ){
         alastname[i] = lastname + i; 
         aovertimepay[i] = overtimepay + i;
         ataxamount[i] = taxamount +i;
         anetpay[i] = netpay + i; } //for
    
 while (!sorted){
         sorted = 1;
   
   for( j = 0; j < n - 1; j++ ){  
      if ( *anetpay[j] > *anetpay[j+1] ){ 

         temp = anetpay[j];
         anetpay[j] = anetpay[j+1];
         anetpay[j+1] = temp;
         
         tempa = alastname[j];
         alastname[j] = alastname[j+1];
         alastname[j+1] = tempa;  
         
         tempb = aovertimepay[j];
         aovertimepay[j] = aovertimepay[j+1];
         aovertimepay[j+1] = tempb; 
         
         tempc = ataxamount[j];
         ataxamount[j] = ataxamount[j+1];
         ataxamount[j+1] = tempc; sorted = 0;
          
              }//if
         }//for
 }//while
}//sort




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class payroll {
ifstream fin;
public: string lastname; 
char ms, paystatus;
int employeeid, i;
float taxrate;
double hoursworked, overtimehours, regularhours, hourlyrate, regularpay, minnp, maxnp, taxamount, netpay, grosspay, overtimepay, yearlysalary;
virtual double findgrosspay();
double findnetpay(), maxnet(double, int), minnet(double, int);
void settingthevariables(char[], int, char, char, double, double, double, double, double, double);
void sortdata(char[],double[],double[],double[]);
void printheaders();
void printdata();
void findtaxamount();
void printminmax(double, double);
payroll();
~payroll();
};
I forgot this :

1
2
3
4
5
6
7
8
9
10
11
12
13
void payroll::settingthevariables(char alastname[], int aemployeeid, char ams, 
char apaystatus, double ahoursworked, double ahourlyrate, double ayearlysalary, double ataxamount, double anetpay, double aovertimepay) {
     lastname = alastname;
     employeeid = aemployeeid;
     ms = ams;
     paystatus = apaystatus;
     hoursworked = ahoursworked;
     hourlyrate = ahourlyrate;
     yearlysalary=ayearlysalary;
     taxamount=ataxamount;
     netpay=anetpay;
     overtimepay= aovertimepay;
}
(ref. OP's post at 12.26pm)
the function declaration in your class shows that you want to process char [] and double [] type datas, but in main you've declared 'overtimepay', 'taxamount' and 'netpay' as double -line 6 and 25.

And in your original post you've declared that your sortdata function expects an integer too, why were it removed from the new function? Isn't 'n' needed to process your array?

(ref. OP's post at 12.26pm)
does the function work? have you tested it?
Last edited on
No it doesnt work. I can not compile it. I am working on it now.
I tried to use char [], double [].... in main (line 25) and now I get a " expected primary expression before ' char'. Any ideas?
Guys, any thoughts?
If you mean you wrote:
double[] a, b, c;
That's incorrect. You can't declare arrays that way.
So this is wrong? void sortdata(char[],double[],double[],double[]);
Topic archived. No new replies allowed.