我的计算函数没有返回任何东西
My calculation function is not returning anything?
我的函数返回0?
int ResizeLockRatio( int width, int height, int desired )
{
int returnValue = ( height / width ) * desired;
return returnValue; // returns 0?
}
int lockedRatioHeight = ResizeLockRatio( 1920, 1200, 1440 );
任何想法?
int returnValue = ( height / width ) * desired;
你在做整数除法,有时被截断为0。
您正在传递width = 1920, height = 1200
,因此在这种情况下,height/widht =1200/1920
的整数除法将截断为0。
EDIT:你可以尝试先做乘法再做除法,根据"Caption visible ":
int returnValue = ( height * desired ) /width ;
相关文章:
- 模板化接口 - 创建一个泛型模板类以返回任何容器
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- C++ - 声明指向返回任何类型并获取任意数量参数的函数的指针
- 类和构造函数中的函数根本不起作用,并且不返回任何错误
- 为什么套接字中的 recv() 函数不返回任何内容?
- C++如何使虚拟函数返回任何类型的指针
- 返回类型为struct的函数每次调用时都不返回任何内容
- 此程序不返回任何内容
- std::ifstream.read() 不会向我的缓冲区返回任何内容
- 为什么即使输入相等,v3 也不会返回任何内容
- glGetBufferSubData() 不返回任何数据?
- stbi_load() 不返回任何内容,但不返回 null
- 如何处理不保证返回任何内容的函数
- C++递归不返回任何内容
- MySQL++ 不返回任何内容
- stbi_load不返回任何值
- 为什么GetEffectiveRightsFromAcl在这种情况下不返回任何权利?
- 当将编译器从G 切换到MSVC时,为什么此开关语句不会返回任何内容
- 分配运营商为什么返回任何开始
- 使用 Module32First 获取模块的 modBaseAddr 不返回任何内容