Cannot convert argument 1 from 'float' to 'float[]'

Asked 2 years ago, Updated 2 years ago, 59 views

#include <iostream>
using namespace std;

float func(float a[]);

int main()
{
    float x[3] = { 1.5, 2.5, 3.5 };

    *cout << func(x) << endl;*
}

float func(float a[])
{
    float sum = 0;
    for (int i = 0; i < 2; i++)
        sum += a[i];
    return sum;
}

I want to make a slight change here and find the sum of x[1] and x[2]. Therefore, when I changed cout << func(x) << endl; to cout << func(x[1]) < endl;, the error of argument 1 cannot be converted from 'float' to 'flat'. How do I solve this problem?

c c++ conversion

2022-09-20 11:29

1 Answers

x[1] must be preceded by &x[1] indicating the address.

That is, cout << func(x[1]) < endl; instead of cout <<< endl;.


2022-09-20 11:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.