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;
}
メイン関数で「x is undeclared」(変更できません) と言い続けるため、関数がコンパイルされません。何が間違っていますか?
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;
}