陷入困境的初学者:C 编程

发布于 2024-09-18 16:00:19 字数 1272 浏览 3 评论 0原文

我这个学期正在上 C 编程课程,尽管没有满足先决条件,但不知怎么的还是被允许注册的。我以为我还能应付得来,但现在我已经过了放弃的地步,我发现自己完全迷失了。

对于我当前的作业,我应该创建一个程序来执行一些简单的三角运算并显示结果。主要思想是有一栋建筑物,我站在离它一定距离的地方。

对于 A 部分,我必须计算建筑物的高度,假设我站在距建筑物 120 米的地方,并以 30 度角(正/负 3 度)倾斜头部并观察顶部。

B 部分,假设建筑物高 200 英尺,而我站在 20 英尺外。我必须倾斜多少角度才能看到顶部?

C 部分,根据 B 部分的信息,我的头到建筑物顶部的距离(斜边)有多远?

到目前为止,我已经写了:

    #include <stdio.h> 
    #include <math.h>
    #define MAX_ANGLE 33
    #define MIN_ANGLE 27
    #define DIST_A 120
    #define DIST_B 20
    #define HEIGHT_B 200
    #define PI 3.14159

    int main()
    (

    double MIN_ANGLE_R, MAX_ANGLE_R;

 MIN_ANGLE_R = MIN_ANGLE * (PI / 180);
 MAX_ANGLE_R = MAX_ANGLE * (PI / 180);
 min_height = DIST_A * tan(MIN_ANGLE);
 max_height = DIST_A * tan(MAX_ANGLE);
 angle = atan(HEIGHT_B/DIST_B)/(PI/180);
 hypotenuse = HEIGHT_B/tan(angle);

 printf ("The minimum height is %6.2f meters.\nThe maximum height is%6.2f meters.\n\n",min_height,max_height);
 printf ("The angle that youw ill tilt your head to see\nthe top of the building is %3.2f feet.\n",angle);
 printf ("The distance from your head to the top of the building is %6.2f feet.\n",hypotenuse);

 return 0;
)

当我尝试编译程序时,我不断收到我不知道如何阅读的错误。如果有人可以通读我的程序,并告诉我缺少什么,这将是一个巨大的帮助。

I am taking a C programming class this semester, and was somehow allowed to register despite not fulfilling the prerequisite. I thought I would still be able to handle it, but now that I have passed the point of no return for dropping it, I find myself completely lost.

For my current assignment, I am supposed to create a program that does a few simple trig operations and display the results. The main idea is that there is a building, and I am standing a certain distance from it.

For part A, I have to calculate the height of the building assuming I am standing 120 meters from the building and am looking at the top while tilting my head at a 30 degree angle (plus/minus 3 degrees).

Part B, assumes the building is 200ft tall, and I am standing 20ft away. What would be the angle I would have to tilt my head to see the top?

Part C, given the info in part B, how far is the distance (hypotenuse) from my head to the top of the building?

So far, I have written this:

    #include <stdio.h> 
    #include <math.h>
    #define MAX_ANGLE 33
    #define MIN_ANGLE 27
    #define DIST_A 120
    #define DIST_B 20
    #define HEIGHT_B 200
    #define PI 3.14159

    int main()
    (

    double MIN_ANGLE_R, MAX_ANGLE_R;

 MIN_ANGLE_R = MIN_ANGLE * (PI / 180);
 MAX_ANGLE_R = MAX_ANGLE * (PI / 180);
 min_height = DIST_A * tan(MIN_ANGLE);
 max_height = DIST_A * tan(MAX_ANGLE);
 angle = atan(HEIGHT_B/DIST_B)/(PI/180);
 hypotenuse = HEIGHT_B/tan(angle);

 printf ("The minimum height is %6.2f meters.\nThe maximum height is%6.2f meters.\n\n",min_height,max_height);
 printf ("The angle that youw ill tilt your head to see\nthe top of the building is %3.2f feet.\n",angle);
 printf ("The distance from your head to the top of the building is %6.2f feet.\n",hypotenuse);

 return 0;
)

When I try compiling the program, I keep getting errors that I don't know how to read. IF anyone could read through my program, and tell me what's missing, it would be a huge help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

草莓酥 2024-09-25 16:00:20

您必须使用“{ ... }”而不是“( ... )”打开和关闭 main()。另外,您必须声明您正在使用的所有变量(不仅仅是 MIN_ANGLE_R 和 MAX_ANGLE_R)。

You have to open and close main() with "{ ... }" instead of "( ... )". Also, you have to declare all the variables you are using (not just MIN_ANGLE_R and MAX_ANGLE_R).

笑梦风尘 2024-09-25 16:00:20

我不是 C 程序员,但我怀疑你的三角函数以弧度工作,而且你似乎正在通过学​​位。

I'm not a C programmer, but I suspect your trig functions work in radians and you seem to be passing degrees.

玻璃人 2024-09-25 16:00:19
  1. 不要混淆 (){}。它们的含义不同。
  2. 声明你的变量。
  1. Don't confuse () and {}. They mean different things.
  2. Declare your variables.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文