My function won't compile as it keeps saying "x is undeclared" in the main function (can't be modified), what am I doing wrong?
int main(){
printf("\nsquare root test 1: enter a number\n");
scanf("%f",&x);
printf("root(%.2f) = %.4f\n", x, squareRoot(x, .001));
getchar();
return 0;
}
For completeness, this is the implementation of the squareRoot
function:
float squareRoot(float value, float error){
float estimate;
float quotient;
estimate = 1;
float difference = abs(value - estimate * estimate);
while (difference > error){
quotient = value/estimate;
estimate = (estimate + quotient)/2;
difference = abs(value - estimate * estimate);
}
return difference;
}