A pointer name is a variable just like any other named variable. Simply put, a variable is something that can store different values, i.e. it varies. Here is an example of how a pointer can store different addresses:
Code:
int num1 = 10;
int num2 = 20;
int* p = &num1;
cout<<*p<<endl;
p = &num2;
cout<<*p<<endl;
1) Don't declare global variables. Get rid of these:
Code:
int iLow=0;
int iHigh=0;
double dLow=0;
double dHigh=0;
2)Unless typing the word "void" gives you pleasure do this:
3)
Code:
void GetMeasurement()
{
int x=0;
double y=0;
int *iDist1=0;
double *dDist2=0;
cout<<"Measurement in feet: "<<endl;
x=GetInt(0, 1000);
iDist1=&x;
cout<<" "<<endl;
cout<<"Measurement in inches:"<<endl;
y=GetDouble(0.0, 11.999);
dDist2=&y;
}
All variables declared in a function(sometimes called "local" variables) are destroyed when the function ends. At the top of the function, you declare the variable:
Code:
double* dDist2 = 0;
and at the bottom of the function you assign an address to dDist2:
As soon as execution proceeds to the closing brace of the function on the next line, dDist2 is destroyed and no longer exists. Therefore, assigning a value to dDist2 is pointless. There is still a variable named dDist2 back in main(), but that is a different variable. That leads to a general rule: don't
declare a variable with the same name as a variable elsewhere in your program. You declare a variable when you list a type and a name and optionally initialize it. If you know you've declared a variable with a specific name elsewhere in your program, do not declare another variable with the same name.
I would also suggest you abandon your notation:
and adopt this notation instead:
That clearly separates the type of the variable from the variable name. The type is int*(pointer to int) and the variable name is iDist1.
See if that helps you get your program working.