在c ++中从double转换为float

时间:2015-09-28 07:10:53

标签: c++ pass-by-reference floating

我是编程新手。这是我的任务的一部分,需要使用pass-by-reference。在我编译它并分别输入win,draw和loss的值之后,它什么都没有返回。我不知道是否是由于调用函数或浮点问题引起的。

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;

    }

2 个答案:

答案 0 :(得分:0)

对我好一点。

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

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

确实,正如@David Hefferman建议的那样,学会使用调试器。将在(非常接近)未来节省大量时间。

答案 1 :(得分:0)

对我来说也很好看。你知道你必须在他们自己的行上逐个添加数字,例如5,3,4?