C 我应该在条件语句中更改什么以生成正确的三角形分类?

C 我应该在条件语句中更改什么以生成正确的三角形分类?,c,ubuntu-16.04,C,Ubuntu 16.04,我想让用户输入任意三个值来表示三角形边的尺寸。代码中的条件语句将对边是否构成三角形进行分类。如果它确实构成三角形,它将显示三角形是不等边三角形还是直角三角形,或者两者都是 #include <stdio.h> int main(void) { //Declare the variables for the sides of the triangle float a; //first side float b; //second side float c; /

我想让用户输入任意三个值来表示三角形边的尺寸。代码中的条件语句将对边是否构成三角形进行分类。如果它确实构成三角形,它将显示三角形是不等边三角形还是直角三角形,或者两者都是

#include <stdio.h>  

int main(void)  
{  
//Declare the variables for the sides of the triangle  
float a; //first side  
float b; //second side  
float c; //third side  
float scalene;  //check for scalene  
float right; //check for right  
float ans; //check if sides are a triangle  
float rep; //check if user wants to continue after the sides are not a 
triangle  

//Get user inputs for the sides of the triangle  
printf("Input the first side of the triangle: ");  
scanf("%f", &a);  

printf("Input the side for the second side of the triangle: ");  
scanf("%f", &b);  

printf("Input the last side of the triangle: ");  
scanf("%f", &c);  

//Conditional statements:  

//Determine if the sides make up a triangle  
>if ((a+b)<c || (b+c)<a || (a+c)<b)  
>{  
ans=0;  
}  
else  
{  
ans=1;  
}  
//If the sides make up a triangle, is the triangle scalene? If scalene, 
//each side is unique to the others  
for (ans=1;ans<3;ans++)  
{  
if (a==b || a==c || b==c)  
{  
scalene=0;  
>}  
else  
{  
scalene=1;  
}  
//if the sides make a right triangle, they would satisfy one of the 
//following Pythagorean theorem  
if ((a*a+b*b)==(c*c) || (b*b+c*c)==(a*a) || (a*a+c*c)==(b*b))  
{  
right=1;  
}  
else  
{  
right=0;  
}  

for (ans=0;ans<2;ans++)  
>{  
printf("Your sides do not make a triangle. Enter 1 if you would like to 
input new values. Enter any other number to finish: \n");  
scanf("%f", &rep);  
}  
if (rep==1)  //repeat the steps again  
{  
printf("Input the first side of the triangle: ");  
scanf("%f", &a);  

printf("Input the side for the second side of the triangle: ");  
scanf("%f", &b);  

printf("Input the last side of the triangle: ");  
scanf("%f", &c);  
>}  
else  
{  
printf("Thank you for using Triangle Check. Have a nice day!");  
return 0;  
}  
}  

//Display the results to the user  
if (scalene==1 && right==1)  
{  
printf("Your triangle is both a scalene and right!");  
return 0;  
}  
else if (scalene==0 && right==1)  
{  
printf("Based on your sides, it is a right triangle!");  
return 0;  
}  
else if (scalene==1 && right==0)  
{  
printf("Based on your sides, it is a right triangle!");  
return 0;  
}  
else  
{  
printf("Your triangle is neither right or scalene.");  
return 0;  
}  


 return 0;  
 }  
#包括
内部主(空)
{  
//声明三角形边的变量
浮动a;//第一面
浮点b;//第二个边
浮点c;//第三方
float scalene;//检查是否存在scalene
向右浮动;//检查是否向右浮动
float ans;//检查边是否为三角形
float rep;//检查用户是否希望在侧边未对齐后继续
三角形
//获取三角形边的用户输入
printf(“输入三角形的第一条边:”);
scanf(“%f”、&a);
printf(“输入三角形第二条边的边:”);
scanf(“%f”和“b”);
printf(“输入三角形的最后一边:”);
scanf(“%f”、&c);
//条件语句:
//确定边是否构成三角形

>如果((a+b)您的逻辑混乱,因此您感到困惑。摆脱
ans
-您不需要它。构建您的程序以立即响应内容。摆脱您不需要的循环。(此程序根本不需要任何循环。)

例如,当检查是否为三角形时,请检查,如果失败,请退出

然后继续进行下一个测试

Flaggy程序(您使用的
ans
scalene
right
等只报告真值的程序)对您没有帮助。请避免使用技巧


祝你好运!

将所有信息放入html注释中,这样它们就看不见了,这真的是一个毫无帮助的想法。它已经让你投了反对票。赶快采取行动,否则你的理解力不足将使你无法得到一个好答案。“你得到的实际结果是什么?”展示出来,然后解释一下。
if ((a+b)<c || (b+c)<a || (a+c)<b)
{
  puts( "Alas, your sides to not make a triangle." );
  return 1;
}
if (a != b && b != c)
{
  puts( "The triangle is SCALENE." );
}