Every variable in a C program has a specific type. Right now, the types that
are of interest to us are the numerical types. The two primary C numerical
types are:
- int, for integers.
- float, for floating-point numbers.
To declare a variable in C, you put a line containing the variable's type and
name on a line after the opening curly brace `{' at the top of the
main function. For example, the statement:
int count;
declares that there is a variable named count and that it can contain
integer values (and only integer values). You can declare several
variables of the same type on a single line by separating the variable names
with commas. For example:
float ankle_x, ankle_y;
declares that there are two variables named ankle_x and ankle_y
that can contain floating point (real number) values.
Take a look at the ``joints.c'' program and identify the variable
declarations. Now let's try something. Our program currently determines the X
and Y coordinates of the squatter's knee joint. Let's start modifying the
program so that it can compute the coordinates of the hip as well. What
additional pieces of information must the program be told in order to
do this?
Click here for the answer
Besides these values, what new quantities must the program calculate?
Click here for the answer
Add the appropriate variable declarations to the ``joints.c'' program,
immediately after the declarations that are already in the program. Don't
worry about writing any other code--just do the variable declarations for now.
When you are done, click on the button below.
Click here when you are done.
Remember that variable declarations must be placed right after the curly brace
that starts the main function. All of the variable declarations must
come before any other kinds of statements in the program or function.
If you put a variable declaration in a place it doesn't belong, the compiler
will complain when you tell it to compile your program.
Eric N. Eide
Hamlet Project
Department of Computer Science
University of Utah