Search code examples
cprogramming-languages

Stuck as a Beginner: C Programming


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.


Solution

    1. Don't confuse () and {}. They mean different things.
    2. Declare your variables.