#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?
x[1]
must be preceded by &x[1]
indicating the address.
That is, cout << func(x[1]) < endl;
instead of cout <<< endl;
.
© 2024 OneMinuteCode. All rights reserved.