c++ - 在 C++ 中从 double 到 float 的转换

标签 c++ pass-by-reference floating

我是编程新手。这是我的作业的一部分,需要使用传递引用。在我编译它并分别输入 win、draw 和 loss 的值后,它什么也没有返回。不知道是调用函数的问题还是 float 的问题。

void Cfunction(int win, int draw, int loss, float& point)

{
point = win * 2.5f + draw * 1 + loss * 0;
}

int main(void)
    {
        int win, draw, loss;
        float point;
        cout << "Please input the game record in the following order: win draw loss " << endl;
        cin >> win >> draw >> loss;

        Cfunction(win, draw, loss, point);
        cout << "The total score for the team is " << point << endl;

    }

最佳答案

我觉得不错。

您可以验证您的 cin >> ...已通过添加 cout << "calculatin total score...." << std::endl; 完成.

(注意:std::cin >> wins 也有通过引用传递的 wins 变量 :))

确实,正如@David Hefferman 所建议的那样,学习使用调试器。将在(非常近的) future 为您节省大量时间。

关于c++ - 在 C++ 中从 double 到 float 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32817457/

相关文章:

c - 在 C 中通过引用传递数组?

c - 为什么作为函数参数时 type arrayp[] 与 type* arrayp 相同?

Java 对对象的引用

python - 用小数替换 float 会导致错误

c++ - 如果在着色器中未使用绑定(bind)属性位置,是否会有惩罚?

c++ - 在 SSE 中比较时的奇怪行为

c++ - 具有私有(private)构造函数的类私有(private)继承的工作机制

c++ 数组元素的别名

linux - 在较旧的 Linux Svrs (Redhat EL 5.7) 上使用最新的 GCC(4.8.1)

c++ - 是否可以对 float 逼近的不同形式进行分类