There are several ways to get specific numbers into your
program, say for latitude and longitude: You can write them in
explicitly, you can put them in as definitions, you can put them
in as initial values of variables, you can compute them, you can
read them from standard input using scanf()
, you can read
them from a named file, or you can get them as ``arguments'' from
the command line used to run your program.
For the viewing latitude and longitude, this last way is best.
In the C++ language, the main program can look like
main(int argc, char** argv) { view_lat_deg = (argc>1) ? atof(argv[1]) : 0 ; view_long_deg = (argc>2) ? atof(argv[2]) : 0 ; ... }
Explanation: argv
is a list of strings (argc
of them),
of which the first is the name of the calling program [not needed
here] and the rest are the arguments as strings. Thus the first
argument is argv[1]
, as a string of characters even though
for this program it represents a number. The atof()
function converts this alphanumeric string to a floating number.
(This function needs #include <math.h>
, but you will
already have included that line because of the sine and cosine
functions.) The ?:
expression says to use the given argument
if it is present or 0
otherwise.