C ++我的代码不起作用,我不知道原因

时间:2019-12-29 00:20:08

标签: arrays c++11 vector

我需要有关此代码的帮助。我不知道为什么我的程序无法正常运行,并且只重复打印了第一句话“请输入十个整数以填充数组”。这就是我得到的。

请输入十个整数以填充数组: 12345678910 请输入十个整数以填充数组: 请输入十个整数以填充数组: 请输入十个整数以填充数组:

我更改了代码和方括号,但该程序对我不起作用。我没有太多的编程经验,并且我的代码没有发现问题。这是代码。

//This program transpose an array and create a vector with even elements of the array.
//This program define a function called fillArray to fill a one-dimensional array with ten integers entered by user.
//A function called printArray to print an array and a function called transpose to transpose the array entered by user.
//Even elements of transpose array should are copied in a vector.


#include <iostream>
#include <vector>

using namespace std;

int main()

{

    void fillArray(); // Function to fill the array with integers entered by user.

    {
        int Array[10];
        int i;

        for (i = 0; i < 10; i++) // loop for the numbers entered by the user.

        {
            cout << "Please enter ten integers for fill the Array: " << endl; //This ask the user for the numbers of the array
            cin >> Array[i];
        }
        cout << endl;

    }

}

void printArray(int Array[]) // Function that prints the array.

{
    int i;
    {

        for (i = 0; i < 10; i++)

        {
            cout << " Original Array: ";

            cout << Array[i] << " ";
            cout << endl;
        }
    }

    void transpose(int Array[]); //Function to transpose array.

    {
        {

            int i; //For the numbers entered by user.
            int j = 9; //
            int ArrayJ;// For transpose Array with integers entered by user.

            for (i = 0; i < 5; i++)

            {
                ArrayJ = Array[i];
                Array[i] = Array[j];
                Array[j] = ArrayJ;
                ArrayJ--;
            }
        }

        vector<int> vector(Array, Array + 10); // Vector for even elements of the Array.

        for (int i = 0; i < 10; ++i)

        {
            if (Array[i] % 2 == 0) //Condition for even numbers.
            {
                vector.push_back(Array[i]);
            }

            //Prints even numbers

            cout << "Even Vector:";
            for (i = 0; i < 5; i++)

            {
                cout << Array[i] << " ";
            }
            cout << "/n";
        }

    }

}

0 个答案:

没有答案