C++,函数不返回双精度
C++, function doesn't return double
我的代码没有返回双值z,而是只返回1,为什么?
#include <iostream>
#include <fstream>
using namespace std;
double road(int s, int v, int max )
{
double t;
t = (s/v);
return t;
}
int main()
{
int s[2]={0};
int v[2]={0};
int max;
double z; // result of function
ifstream fd;
fd.open("u1.txt");
fd >> max;
for (int i = 0; i < 2; i++)
{
fd >> s[i] >> v[i];
z = road( s[i], v[i], max );
cout << z << " ";
}
fd.close();
return 0;
}
尝试像一样更改方法
double road(int s, int v, int max )
{
double t;
t = (s/(double)v);
return t;
}
int/int将产生一个整数。所以你需要将分子或分母转换为二重。
相关文章:
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- C 字符串返回字符串的整数/双精度/长整型值
- C++:strod() 和 atof() 没有按预期返回双精度
- f 是指向函数的指针,该函数采用 int,并返回指向不带任何内容并返回双精度的函数的指针
- 从 C++ 中的函数返回双精度的问题
- atof() 返回浮点数而不是双精度
- 我想读取文本文件中的所有内容(但文本文件中只有一个双精度值),转换为双精度值并返回值
- 如何在 Linux asm 中正确返回双精度值
- 如何调用返回双精度或字符串并将其保存在地图上但作为对象的类的方法
- 编译C++代码以.EXE返回双精度
- 视觉对象 返回 C++ 中的双精度值
- 为什么 boost::geometry::d istance 使用 model::d 2::p oint_xy<float> 返回双精度而不是浮点数?
- 从模板函数返回双精度或复数<double>
- C++ 从矩阵返回双精度**
- C++,函数不返回双精度
- PInvoke:返回双精度数组的问题
- 如何调用从Python返回双精度向量的c++函数
- 如何在c++中从pthread返回双精度值
- 函数返回双精度当预期的长
- 为什么从浮点返回方法返回双精度不会在 c++ 中导致任何错误/警告