Re: Global/Local Variables
The problem is purely in the second routine. You are declaring radius as the function parameter, and also within the body of the function. Both of these are being declared local to the routine - this is not allowed.
Hope this helps,
- Nigel
Re: Global/Local Variables
So how can I modify my code to keep the global variable radius as 5, and also make a local variable in the Area function?
Re: Global/Local Variables
double Area() // look ma, no hands (or parameter)
{
area = (pi * ::radius * ::radius); // using global radius (twice)
double radius = 2; // local variable only
cout<<"The Radius In the Area() Function is: "<<radius<<endl; // local again
return area; // was calculated based on global
}
If you want to access a global variable (or routine) from within a function, use the :: global scope modifier.
Hope this helps,
- Nigel