Can someone create this array for me?

+1 Mani Sandhu · January 17, 2016

I am trying to fill up the elements in an array using a loop. I want the user to add each element when prompted. 

Thnqqq :)

Post a Reply


Oldest  Newest  Rating
+1 Laura Lee · January 17, 2016
for variable i starts at 0; runs while i is less than number of elements; increment i by one
    assign array at index i to some value x
0 Mani Sandhu · January 18, 2016

#include <iostream>

using namespace std;

int main()
   int array[5];
    for(int i=0;i<5;i++){
            int x;
            cout<<"Enter the Array Element:"<<endl;
    cout<<"The Array elements are: "<<array;

    return 0;

:( it outputs some hexadecimal value. I want it to output the values That are entered by the user 
0 Mario Ključević · January 18, 2016
Hi Mani,

You can easily fill up your array using loop with a following code:

using namespace std;

int main(){
    int elNum;

    cout << "Enter how many elements you want to add to your array:" << endl;
    cin >> elNum;
    int myArray[elNum+1];

    cout << "Please, enter your elements:" << endl;
    for(int x=1; x<=elNum; x++){
        cout << x << ". element: ";
        cin >> myArray[x];
    return 0;

Have  a nice day:)
0 Laura Lee · January 19, 2016
Mani, you are printing the address at which the array points to. Not an index.
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator