I need some help to take array values from function:
using namespace std;
int i;
double translational_velocity(double x[100],double y[100], int t);
int main()
{ int SCAN_NUMBER;
int obj_num;
cin>>obj_num;
for(int n = 0; n < obj_num; n++)
{ cin>>SCAN_NUMBER;
int t = SCAN_NUMBER;
int x[t];
int y[t];
for(i =0; i < t; i++)
{ cout<<"x = ";cin>>x[i];
cout<<"y = ";cin>>y[i];
}
for(i = 0; i < t; i++)
if(x[0] == x[i] && y[0] == y[i])
cout<<"g";//VFH(x,y);
else
{ v[i] = translational_velocity(x, y, t); /* problem is here, how to get values */
Array's are constant pointers. That means that you can pass an array to a function, initialize the elements there, and then use those values in the main-loop:
#include <iostream>
usingnamespace std;
//function to set the values of an array
void setValues(int array[], int size)
{
//for-loop to go through all elements
for (int i=0;i<size;i++)
{
//store information into the elements
array[i]=i*2;
}
}
int main()
{
//declare array and size
constint SIZE = 5;
int myArray[SIZE];
//set values
setValues(myArray,SIZE);
//print values to the screen
for (int i=0;i<SIZE;i++)
{
cout<<myArray[i]<<endl;
}
//whait before ending the program...
cin.ignore();
//quit the program
return 0;
}