error: cannot convert 'double' to 'double*'

The error is: error: cannot convert 'double' to 'double*' for argument '2' to 'void selection_sort(int, double*)'
Any help would be appreciated.

The problem is in the function call/ function itself at the bottom for 'selection_sort'


#include<string>
#include<iomanip>
#include<fstream>
#include<iostream>
#include<stdlib.h>
using namespace std;

#define SIZE 100 //Max friends

//Selection Sort
void selection_sort(int i, double percent[SIZE]);


//Print Function
string output_function(string name[SIZE], string var1[SIZE], string var2[SIZE], double percent[SIZE], int i);

class fl_friends{
public:
string first;
string last;
string current;
};

int main(int argc, char**argv)
{
int i; //index variable//
string a_name[SIZE]; //Name of Friend
string a_var1[SIZE]; //Correct answers
string a_var2[SIZE]; //Total questions
double percent[SIZE];

fl_friends name, var1, var2; //Same as above attached to class

if(argc != 2){ //Check for arguments//
cerr << "Not enough arguments\n";
exit(1); //If none, exit//
}

ifstream fin; //File of information//
fin.open(argv[1]); //Open file
perror(argv[1]);

i = 0; //Initialize
while(fin >> name.current >> var1.current >> var2.current)
{
a_name[i] = name.current; //Pass to an array
a_var1[i] = var1.current; //''
a_var2[i] = var2.current; //''
percent[i] = atof(var1.current.c_str())/atof((var2.current.c_str()));
i++; //Increase count
}

selection_sort(i, percent[SIZE]); Error is Here

output_function(a_name, a_var1, a_var2, percent, i); //Run print func

return 0;
}

//Functions

void selection_sort(int i, double percent[SIZE]) Error is Here
{
for (int count2 = 0; count2 < i; count2++)
{
int min = count2;
for (int j = count2 + 1; j < i; j++) {
if (percent[j] < percent[min]) {
min = j;

}
}
if (count2 != min) {
int swap = percent[count2];
percent[count2] = percent[min];
percent[min] = swap;
}
}

exit(1);
}

Instead of percent[SIZE], just pass percent in function selection_sort. Because, when you say selection_sort(i, percent[SIZE]) then you are sending the value stored at percent[SIZE], which is a double value.
Whereas in the function, selection_sort(int i, double percent[SIZE]) you expect the argument to be an array.

Hope this helps !
Last edited on
percent[SIZE] is of type double, since it refers to the SIZEth element (0-based) of the array.

percent, by itself, is of type double[SIZE].

percent[SIZE] is a specific element in percent (one that's beyond the end of the array, by the way). To pass the array, pass percent.

selection_sort(i, percent);
I figured that out but thanks. New problems now! :)
Topic archived. No new replies allowed.