- #1
- 1,120
- 1
I recently came up with a bit of a mathematical problem for myself and decided I needed a bit of code to help me. My understanding of C++ is pretty basic and I seem to have found myself stuck mixing arrays and functions.
I wrote the function:
But in my main() the line:
Where poss[] is an array of length tri and tri is some integer, returns the compiler error:
Any ideas?
Also I want to write a function which goes something like:
But C++ seems to have no concept of returning arrays, any idea what I need to be looking at to get around this? Thanks for any help at all.
I wrote the function:
Code:
int worko (int c[], int tri)
{
//turns the array into the number it represents
int ans = 0;
int i;
for (i=0; i < tri; i++)
{
ans = ans + 2^c[i]*(i+1);
}
return ans;
}
But in my main() the line:
Code:
int test = worko(poss[],tri);
Where poss[] is an array of length tri and tri is some integer, returns the compiler error:
68 C:\Documents and Settings\Administrator\My Documents\sillyproblem.cpp expected primary-expression before ']' token
Any ideas?
Also I want to write a function which goes something like:
Code:
int addone[] (int d[], int tri, int log)
{
d[0] = d[0]+1;
int j;
for (j=0; j < tri; j++)
{
if (d[i] > log)
{
d[j]=0;
d[j+1]++;
}
}
return d[];
}
But C++ seems to have no concept of returning arrays, any idea what I need to be looking at to get around this? Thanks for any help at all.