C++迭代法求平方根输出结果总是inf怎么办

#include
#include
using namespace std;

int main(){
double a,x,res;
cout<<"请输入正数a:";
cin>>a;

x=a/2.0;

        while(fabs(res-x)>1.0e-5){
    x=res;
    res=(x+a/x)/2.0;
}

cout<<"a的平方根为"<<res<<endl;

system("pause");
return 0;

}

while(fabs(res-x)>1.0e-5)这里res没有初始化啊,在while循环之前给res赋值

res一开始都没有值,就被赋值给x了