What does this error message mean?

<
if (projXmove >= (displayWidth/75)/sqrt(1+(projSlope)(projSlope))) {
projXmove = (displayWidth/75)/sqrt(1+(projSlope)(projSlope));
}

When I try to run this within my program I get the error message “The operator + is undefined for the argument type(s) int, projSlope”

I’m not sure what that means. I feel it may be related to trying to use 1 as an integer value with float type variables, but i’m not otherwise sure how I would fix this.

I suspect you are using JAVA mode so your code should probably be like this

if (projXmove >= (displayWidth / 75) / sqrt(1 + projSlope * projSlope)) {
  projXmove = (displayWidth / 75) / sqrt(1 + projSlope * projSlope);
}

Notice the mutiplication sign (*), you seem to have missed these.

Also in this instance the brackets surrounding projSlope are superfluous and I have added white-space round the math operators for clarity.

This assumes that projXmove and projSlope are both of type float.

In terms of programming logic I believe you can replace the code with the following.

projXmove = max(projXmove, (displayWidth / 75) / sqrt(1 + projSlope * projSlope));

I leave you to work out why :grin:

2 Likes

This is sometimes from incorrect formatting of code.
Or just an error.

@WillyGrz ,

Please read:

Your code is not formatted correctly.

:)

@glv thanks for the comment about formatting, forgot about that :wink:

Sorry my answer was incomplete. Since you are performing maths the + sign expects a numeric literal or numeric variable for both arguments so I suspect that the variable projSlope is not a numeric variable.

1 Like