Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
void computeXY(double p[2],int x,int y)
-imagine the x y values being the width and height of a triangle
-the function should set p to the width and height of that triangle when the hypotenuse is 1
-should basically divide x and y by the hypotenuse of the triangle they make
-p[0] = x
-p[1] = y
-example: computeXY(p,3,4) should set p[0] to 0.6 and p[1] to 0.8

What I have tried:

Don't know how to start. I am still struggling with how to approach this question.
Posted
Updated 29-Nov-17 20:35pm
Comments
cvogt61457 29-Nov-17 20:43pm    
First, you need to determine the equations to use.
Be able to solve the problem on paper with your equations.
Then you write your program.
It's not too early to learn how to use the debugger.

Start with Pythagoras:
x2 + y2 = z2

You are given the width x and height y of the triangle, so you can calculate z:
z = Square Root(x * x + y * y)

You now need to know the ratio of this triangle to a triangle with a z of 1:
z1 = 1 / z;
You can then multiply x and y by z1 and you have the values.
 
Share this answer
 
At first you should understand the task, for that inform about trigonometry. Your width and height are the input for the math at a right angled triangle. With the law of pythagoras you will get the hypothenuse. With that result you divide and set the output into the pointers. Use float for computation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900