Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数学四舍五入。h不正确 我正在使用代码修道院的任务来完成C++的工作。 我试图通过导入math.h来使用舍入函数,它适用于我尝试输入的每一个值,除了一对 当我将4991264除以4并四舍五入时,它输出的结果是1.24782e+06 #include <iostream> #include <math.h> using namespace std; int getTotal(){ int total; cin >> total; return total; } void doMath(int total){ int count; double holder; double holder2; double solution; solution = 0; count = 0; while (count != total){ cout << "enter a number "; cin >> holder; cout << "enter a number "; cin >> holder2; solution = (holder / holder2); cout << round(solution) << "\n"; ++count; } } int main(){ int total = getTotal(); doMath(total); return 0; } #包括 #包括 使用名称空间std; int getTotal(){ 整数合计; cin>>总数; 返回总数; } void doMath(整数总计){ 整数计数; 双支架; 双保持器2; 双溶液; 溶液=0; 计数=0; while(计数!=总数){ 支架; cout>holder2; 解决方案=(持有者/持有者2); cout_C++ - Fatal编程技术网 >总数; 返回总数; } void doMath(整数总计){ 整数计数; 双支架; 双保持器2; 双溶液; 溶液=0; 计数=0; while(计数!=总数){ 支架; cout>holder2; 解决方案=(持有者/持有者2); cout,c++,C++" /> >总数; 返回总数; } void doMath(整数总计){ 整数计数; 双支架; 双保持器2; 双溶液; 溶液=0; 计数=0; while(计数!=总数){ 支架; cout>holder2; 解决方案=(持有者/持有者2); cout,c++,C++" />

数学四舍五入。h不正确 我正在使用代码修道院的任务来完成C++的工作。 我试图通过导入math.h来使用舍入函数,它适用于我尝试输入的每一个值,除了一对 当我将4991264除以4并四舍五入时,它输出的结果是1.24782e+06 #include <iostream> #include <math.h> using namespace std; int getTotal(){ int total; cin >> total; return total; } void doMath(int total){ int count; double holder; double holder2; double solution; solution = 0; count = 0; while (count != total){ cout << "enter a number "; cin >> holder; cout << "enter a number "; cin >> holder2; solution = (holder / holder2); cout << round(solution) << "\n"; ++count; } } int main(){ int total = getTotal(); doMath(total); return 0; } #包括 #包括 使用名称空间std; int getTotal(){ 整数合计; cin>>总数; 返回总数; } void doMath(整数总计){ 整数计数; 双支架; 双保持器2; 双溶液; 溶液=0; 计数=0; while(计数!=总数){ 支架; cout>holder2; 解决方案=(持有者/持有者2); cout

数学四舍五入。h不正确 我正在使用代码修道院的任务来完成C++的工作。 我试图通过导入math.h来使用舍入函数,它适用于我尝试输入的每一个值,除了一对 当我将4991264除以4并四舍五入时,它输出的结果是1.24782e+06 #include <iostream> #include <math.h> using namespace std; int getTotal(){ int total; cin >> total; return total; } void doMath(int total){ int count; double holder; double holder2; double solution; solution = 0; count = 0; while (count != total){ cout << "enter a number "; cin >> holder; cout << "enter a number "; cin >> holder2; solution = (holder / holder2); cout << round(solution) << "\n"; ++count; } } int main(){ int total = getTotal(); doMath(total); return 0; } #包括 #包括 使用名称空间std; int getTotal(){ 整数合计; cin>>总数; 返回总数; } void doMath(整数总计){ 整数计数; 双支架; 双保持器2; 双溶液; 溶液=0; 计数=0; while(计数!=总数){ 支架; cout>holder2; 解决方案=(持有者/持有者2); cout,c++,C++,浮点变量保留给定类型的值(在内存中)。 该值以二进制格式以其自身的精度“驻留”在那里。 当必须显示此值或以某种方式输出时,通常会转换为十进制格式。这种转换有时会导致精度损失 无论如何,当您进行精确的算术运算时,如您的示例中所示,一般来说,转换为十进制不是问题。 这里必须理解的是,“打印”值与“显示内存中保存的确切值”不同 对象cout具有预定义的方式来显示您正在计算的值。 精确值没有改变,在这种情况下,这不是一个计算错误的问题 实际上,这只是如何在屏幕上显示该值的问题 用于打印值的格式为:指数表

浮点变量保留给定类型的值(在内存中)。
该值以二进制格式以其自身的精度“驻留”在那里。
当必须显示此值或以某种方式输出时,通常会转换为十进制格式。这种转换有时会导致精度损失

无论如何,当您进行精确的算术运算时,如您的示例中所示,一般来说,转换为十进制不是问题。
这里必须理解的是,“打印”值与“显示内存中保存的确切值”不同

对象
cout
具有预定义的方式来显示您正在计算的值。
精确值没有改变,在这种情况下,这不是一个计算错误的问题
实际上,这只是如何在屏幕上显示该值的问题

用于打印值的格式为:指数表示法,精度为“仅”6位小数

打印时需要提高值的精度,并避免使用指数表示法

请浏览本网站:

因此,例如,以下代码执行此任务(精度为8位小数):


cout你看到什么有“extrange”或“bad”在您获得的输出中?这看起来对我来说是正确的答案。我的
cout
技能有点生疏,但是如果您希望格式化值中的精度有更多位数,您不需要指定您希望格式化值中的精度有更多位数吗?我使用的网站希望得到1247816的答案以及我的所有其他自动输入使用round时自动将格式设置为最接近的整数该算法是正确的,您只是没有正确打印。非常感谢您的回答。我使用了:
cout@jarkia您不理解这个问题,您选择了错误的解决方案(
cout@jarkia:您的其他输入将对应于精度小于6位小数的值。您在问题中显示的值具有8位小数的精度。因此,标准行为是仅显示前6位小数的精度,并使用指数表示法。同样,这是一个输出格式问题。请,进一步研究
cout
显示浮点值的方式,以及如何选择显示相同值的几种不同方式。
  cout << setiosflags(ios::fixed) << setprecision(8) << round(solution) << "\n";