我正在尝试练习制作 if 语句,但运气不佳。现在我正在尝试使用 if 语句制作一个非常简单的三角计算器,但我无法让它工作。实际问题发生在输入三角函数(正弦、余弦、正切)之后。这就是发生的事情。
1. 我编译它
2. 它输出用户提示
3. 我输入函数并回车
4. 程序跳转到一个新的空白行
5. 没有任何反应,如果我按下回车,程序关闭
这是代码本身。如果我做了一些非常愚蠢的事情,请善待,我对 C 很陌生。
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void)
{
float x;
float a, o, h;
float sine, cosine, tangent;
printf("Enter the trig function you wish to calculate: ");
scanf("%f", &x);
if (x == sine)
{ printf("Enter the value of the opposite leg: ");
scanf("%f", &o);
printf("Enter the value of the hypotenuse: ");
scanf("%f", &h);
sine = o / h;
printf("The sine is equal to %f", sine);
}
if (x == cosine)
{ printf("Enter the value of the adjacent leg: ");
scanf("%f", &a);
printf("Enter the value of the hypotenuse: ");
scanf("%f", &h);
cosine = a / h;
printf("The cosine is equal to %f", cosine);
}
if (x == tangent)
{ printf("Enter the value of the opposite leg: ");
scanf("%f", &o);
printf("Enter the value of the adjacent leg: ");
scanf("%f", &a);
tangent = o / a;
printf("The tangent is equal to %f", tangent);
}
getch();
}
感谢所有真正有帮助并且对我缺乏理解的人并不粗鲁,我没有意识到我必须添加一个数字字符而不仅仅是一个字符。