我是编程新手。这是我的作业的一部分,需要使用传递引用。在我编译它并分别输入 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/