如何在C+中显示长度超过1个小数点的答案+; 我的C++程序在使用命名空间和填充之后有一个类似的操作。 cout<<"Please type the data"; cin>> a; z = a/4; cout<<"The answer is"<< z; couta; z=a/4; coutcoutcout
使用适当的类型:如何在C+中显示长度超过1个小数点的答案+; 我的C++程序在使用命名空间和填充之后有一个类似的操作。 cout<<"Please type the data"; cin>> a; z = a/4; cout<<"The answer is"<< z; couta; z=a/4; coutcoutcout,c++,decimal,C++,Decimal,使用适当的类型: double z = 0.; z = 54/4.; std::cout << z << std::endl; double z=0。; z=54/4。; std::cout使用适当的类型: double z = 0.; z = 54/4.; std::cout << z << std::endl; double z=0。; z=54/4。; std::cout您的问题是将a和z定义为int类型。相反,将它们定义为dou
double z = 0.;
z = 54/4.;
std::cout << z << std::endl;
double z=0。;
z=54/4。;
std::cout使用适当的类型:
double z = 0.;
z = 54/4.;
std::cout << z << std::endl;
double z=0。;
z=54/4。;
std::cout您的问题是将a和z定义为int类型。相反,将它们定义为double,您的问题将得到解决
double a, z;
cout<<"Please type the data";
cin>> a;
z = a/4;
cout<<"The answer is"<< z;
双a,z;
库塔;
z=a/4;
cout您的问题是将a和z定义为int类型。相反,将它们定义为double,您的问题将得到解决
double a, z;
cout<<"Please type the data";
cin>> a;
z = a/4;
cout<<"The answer is"<< z;
双a,z;
库塔;
z=a/4;
在您的示例中,变量a
和z
是什么类型?如果它们是float
,它应该自动工作。在您的示例中,变量a
和z
是什么类型的?如果它们是浮动的,它应该自动工作。