C++的程序

来源:百度知道 编辑:UC知道 时间:2024/06/27 14:41:57
#include <iostream>
using namespace std;
int main()
{
double c,f;
cin>>f;
c=5/9*(f-32);
cout<<setiosflags(ios::fixed)<<c<<endl;
return 0;
}

是什么地方错了呢???

你是温度转换的吧?
注意:c=5/9*(f-32); 5/9当整数用,等于零了.
所以改为:
c=5.0/9*(f-32); 或强制转换类型:c=double(5)/9*(f-32); 都是可以的.总之你记住一点:整型相除,没有小数部分.
楼上说得好像也是,但不是根本问题,你调试一下.

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double c,f;
cin>>f;
c=5/9*(f-32);
cout<<setiosflags(ios::fixed)<<c<<endl;
return 0;
}
setiosflags 在iomanip