调用函数后,程序不会运行到最后

Program wont run to the end after function is called

本文关键字:运行 最后 程序 函数 调用      更新时间:2023-10-16

我编写了一个程序来接受数组中的 15 个整数值,然后将这个数组传递给一个函数,该函数将每个偶数索引值乘以 4。

目前程序显示初始数组,但似乎在显示修改后的数组之前它被挂起了。

请帮助我理解为什么该程序卡在这里!

    int main(){
    const int SIZE = 15;
    int quad[SIZE] = {};
    void quadruple(int[], const int);
    cout << "Enter 15 integer values into an array." << endl;
    for (int i = 0; i < SIZE; i++)                               // Accept 15 int values
    {
        cout << i << ": ";
        cin >> quad[i];
    }
    cout << "Before quadruple function is called: " << endl;
    for (int i = 0; i < SIZE; i++)
    {
        cout << quad[i] << " ";
    }
    cout << endl;
    quadruple(quad, SIZE);
    cout << "After even index value multiplication: " << endl;
    for (int i = 0; i < SIZE; i++)
    {
        cout << quad[i] << " ";
    }
    cout << endl;
    return 0;
}
void quadruple(int values[], const int SZ){
    for (int i = 0; i < SZ; i + 2)                // Multiply even values by 4
    {
        if ((i % 2) == 0)
        {
            values[i] = values[i] * 4;
        }
        else                                      // Keep odd values the same
        {
            values[i] = values[i] * 1;
        }
    }
}
for (int i = 0; i < SZ; i + 2)     

"I + 2"不执行任何操作。

你可能的意思是"i += 2;"。

您的家庭作业是查找有关系统调试器的一些文档。并找到你的橡皮鸭在哪里,正如评论中建议的那样。