这就是问题。
编写一个程序,提示用户输入五个十进制数。然后程序应将五个十进制数相加,将总和转换为最接近的整数 m 并打印结果。
这是我到目前为止得到的:
// p111n9.cpp : Defines the entry point for the console application.
//
#include <iostream>
using namespace std;
double a, b , c , d , e, f;
int main(int argc, char* argv[])
{
cout << "enter 5 decimals: " << endl;
cin >> a >> b >> c >> d >> e;
f = a + b + c + d + e;
return 0;
}
现在我只需要将 sum(f
) 转换为最接近的整数 m
并打印结果。我该怎么做?
最佳答案
"declare m" means say
int m;
如果你说
m = (int)f; // it means the int value of f is assigned to m.
这里甚至不需要强制转换:
m=f; //works just as well
现在你可以打印m了
cout<<m;
关于c++ - 编写一个程序,提示用户输入五个十进制数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2603611/