samedi 28 décembre 2019

C++ My code doesn't work I don't know the reason

I need help with this code. I don't know why my program doesn't work as it should and only the first sentence "Please enter ten integers for fill the Array" was printed repetitively.This is what I get.

Please enter ten integers for fill the Array: 12345678910 Please enter ten integers for fill the Array: Please enter ten integers for fill the Array: Please enter ten integers for fill the Array:

I've changed the code and the brackets and the program does not work for me. I don't have much experience programming and I don't find the problem with my code. Here is the code.

//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";
        }

    }

}

Aucun commentaire:

Enregistrer un commentaire