why does error cannot convert 'double*' to double show up in my cpp code

Viewed 60

So here is the function I was writing

#include <iostream>
#include <math.h>
using namespace std;
double bin2dec(int binary[], int arr_size){
int x;
double y;
int a = 0;
double result_arr[1000];
while(binary[a] == 1 || binary[a] == 0){
    for(y = 0, x = 0; x <= arr_size; ++y, ++x){
        double result = binary[x] * pow(2, y);
        result_arr[x] = result;
    }
    ++a;
  }
return result_arr
}

What my function does is it converts binary to decimal by taking in an integer array and array size it returns a double representing the output but the problem is it says I can't convert 'double*' to 'double' error when I execute it by including it in another file.

1 Answers

The function returns 'results_arr' which is a 'double[]' but the return type is 'double'. If you want to return results_arr you want to use 'double* bin2dec(int binary[], int arr_size){' for the function declaration

Related