Strange Expected Primary Expression Error

Hello everyone, I am new to the forums. I am having some issue with this function I have written. There are a few errors I am having trouble understanding. The frustrating part about this is that this code works when it is not a function and part of a different program. Any way here is the list of errors that it is throwing (I am using g++ to compile on linux)

error2.cpp: In function ‘void sinembed(double*, double*, double, int, int)’:
error2.cpp:60: error: expected primary-expression before ‘=’ token
error2.cpp:60: error: expected `)' before ‘;’ token
error2.cpp:60: error: invalid type argument of ‘unary *’
error2.cpp:60: error: expected `;' before ‘)’ token
error2.cpp:61: error: expected primary-expression before ‘=’ token
error2.cpp:61: error: expected `)' before ‘;’ token
error2.cpp:61: error: invalid type argument of ‘unary *’
error2.cpp:61: error: expected `;' before ‘)’ token

And here is the problematic code:
1
2
3
4
5
6
7
8
9
10
11
void sinembed(double x[MAX], double y[MAX], double amplitude, int templength, int delay)
{
	int count = 0;
	for(int n=0; n<MAX; n++){
		if (count<templength){
			x[n] += amplitude*sin((2*pi*n)/51);
			y[n+delay] += amplitude*sin((2*pi*n)/51);
		}
	count++;
	}
}


Lines 60 and 61 are the same as 6 and 7.

This post was originally in the beginners forums and someone suggested that it could be a problem with using : using namespace std;
Last edited on
1) Is 'pi' defined? I'm assuming it is elsewhere, since that doesn't appear to be one of the errors. Or perhaps you don't have math.h included?
2) You don't appear to actually need the 'count' variable, since you're incrementing it exactly along with n. You could just check for n<tempLength in your 'if' statement, rather than checking count<tempLength.

Otherwise, I can't see what's wrong, syntactically. If you #define pi yourself somewhere, check for this:

1
2
#define pi = 3.14159   //Wrong
#define pi 3.14159     //Right 

...because that equality sign would get substituted into your lines of code as well.
Last edited on
I will admit count is useless. And pi is defined as you have it there:
#define pi 3.14...

I stopped using pi globally like this though. I don't use it anywhere but that function so I just moved it to the subroutine as a simpler variable.

Sorry I shouldn't have posted this again here, there's a better discussion going on in Beginner forums now.
Topic archived. No new replies allowed.