Reputation: 43
#include <stdio.h>
float function (float x, float y);
float function2 (float x, float z);
float function3 (float y, float z);
float main()
{
float x;
float y;
float z;
{
printf("Please insert length of adjacent side");
scanf("%f", &x);
printf("Please insert length of opposite side");
scanf("%f", &y);
printf("Please insert length of the hypotenuse");
scanf("%f", &z);
}
{
if (z = 0){
printf("The length of the hypotenuse is %f", function (x, y));}
else if (y = 0){
printf("The length of the opposite side is %f", function2(x, z));}
else if (x=0){
printf("The length of the adjacent side is %f", function3(y, z));}
}
}
float function(float x, float y) {
return(sqrt(((x*x)+(y*y))));
}
float function2(float x, float z) {
return(sqrt(((z*z)-(x*x))));
}
float function3(float y, float z){
return(sqrt(((z*z)-(y*y))));
}
This is the code that I have to figure out the missing side of a right triangle. The input for the side that you do not know is 0. When I run the program it asks me for all the sides but then it does not go on and give me the answer...Could anyone please explain this? Thanks
Upvotes: 0
Views: 22344
Reputation:
=
is an assignment operator. Replace z = 0
and any others like it with z == 0
if (z == 0){ // = changed to ==
printf("The length of the hypotenuse is %f", function (x, y));}
else if (y == 0){ // = changed to ==
printf("The length of the opposite side is %f", function2(x, z));}
else if (x == 0){ // = changed to ==
printf("The length of the adjacent side is %f", function3(y, z));}
Upvotes: 8