所以昨晚我问了一个关于我试图为练习而做的三角计算器的问题,我又回来了,这个问题与我的上一个问题非常相关。自昨晚以来,我已经修复了计算器,但出于某种奇怪的原因,其中一个 if 语句通过了针对不同 if 语句的测试。这是我的代码-
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int x;
float o, h, a, S, C, T;
enum { sine, cosine, tangent};
printf("Enter the value for the function you wish to calculate\n(Sine = 0 Cosine = 1 Tangent = 2): ");
scanf("%f", &x);
if(x == 0)
{
printf("Enter the value of the opposite leg: ");
scanf("%f", &o);
printf("Enter the value of the hypotenuse: ");
scanf("%f", &h);
S = o / h;
printf("The sine is equal to %f", S);
}
else if(x < 2, x > 0)
{
printf("Enter the value of the adjacent leg: ");
scanf("%f", &a);
printf("Enter the value of the hypotenuse: ");
scanf("%f", &h);
C = a / h;
printf("The cosine is equal to %f", C);
}
else if(x == 2)
{
printf("Enter the value of the opposite leg: ");
scanf("%f", &o);
printf("Enter the value of the adjacent leg");
scanf("%f", &a);
T = o / a;
printf("The tangent is equal to %f", T);
}
else
{
printf("Wat da fack");
}
return 0;
}
发生的情况是余弦测试通过了切线并且切线函数不起作用。和以前一样,我对此还是很陌生,所以请放轻松。顺便说一句,我有两个余弦测试条件的原因是,除非我有这样的条件,否则它不会运行,对此表示赞赏也。