C++ 函数中的引用不';不要在它之外更改项目。C++;

C++ 函数中的引用不';不要在它之外更改项目。C++;,c++,function,reference,C++,Function,Reference,试图通过引用从函数中获取值,但似乎我一直在获取函数调用之前分配的值 void third() { int summ = mainInput(3); int second = 0; cout << "You should pay " << fiveBill(summ, second) << second; } int fiveBill(int summ,int &two) { int five=0; if (su

试图通过引用从函数中获取值,但似乎我一直在获取函数调用之前分配的值

void third()
{
    int summ = mainInput(3);
    int second = 0;
    cout << "You should pay " << fiveBill(summ, second) << second;
}

int fiveBill(int summ,int &two)
{
    int five=0;
    if (summ%2==0)
    {
        two = summ / 2;
    }
    else
    {
        two = (summ - 5) / 2;
        five++;
    }
    while (two>4)
    {
        two -= 5;
        five += 2;
    }
    return five;
}
void third()
{
int summ=主输入(3);
int秒=0;

在C++中,函数调用参数的计算顺序是故意不指定的。编译器完全可以评估<代码>第二版/代码>作为“代码>的参数。您确信函数中赋值给<代码> 2<代码>的值不只是代码> 0 < /代码>?AOR,您确信主输入调用没有返回一些。意外事件?mainInput大多数情况下返回7,所以两个应该返回1,但从未发生过非常感谢