首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

新手请问:C++中对小数点后两位进行四舍五入,结果出现有关问题

2013-09-09 
新手请教:C++中对小数点后两位进行四舍五入,结果出现问题 #includeiostream #includestdlib.husing na

新手请教:C++中对小数点后两位进行四舍五入,结果出现问题
 #include<iostream>
 #include<stdlib.h>
  using namespace std;
    float x;
void main()
  {
   cin>>"a\n";
   cout<<"getA(a):"<<endl;
   system("pause");

  }
   void getA(float x)
   {
   x= int((x+0.005)*100.)/100;
       };
c++ ,c++builder
[解决办法]

#include<iostream>
#include<cstdlib> 

using namespace std;
void getA(double& x);

int main()
{
cout << "Input a: ";
double x;
cin >> x;
getA(x);
cout<< "getA(a): " << x <<endl;
system("pause");
return 0;
}

void getA(double& x)
{
   x= int((x+0.005)*100) / 100.0;
};

热点排行