+ 1

How can I use * instead of pow?

When I run the commented part instead of the other part I get an error "expected ) before ; token ; " float ds = (sqrt(pow((p.getX() - getX()),2) + pow((p.getY()- getY()),2) + pow((p.getZ() - getZ()),2))); /* float ds=sqrt (((p.getX()-getX())*(p.getX()-getX())+ ((p.getY()-getY())*(p.getY()-getY())+ ((p.getZ()-getZ())*(p.getZ()-getZ())); */

12th Jan 2022, 11:56 PM
Nadia
Nadia - avatar
3 Respuestas
+ 1
Remove the first parenthesis '(' from each line They are mismatched and you don't need them
13th Jan 2022, 12:17 AM
Angelo
Angelo - avatar
+ 1
To not confuse, simplifying to understand : float x, y, z; x = p.getX()-getX(); y = p.getY()-getY(); z = p.getZ()-getZ(); float ds = sqrt( pow(x,2) + pow(y,2) + pow(z,2) ); /* float ds=sqrt( (x*x)+(y*y)+(z*z) ); */
13th Jan 2022, 9:31 AM
Jayakrishna 🇮🇳