Thread: C++ arrays

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    C++ arrays


    Hello :)
    i'm trying to make an integer array of an unknown size with unknown elements
    and so far have come up with the following code. but i keep running into errors... can someone please explain to me what i am doing wrong and how to go about doing it some other way? thank you :)

    Code:
    int _tmain(int argc, _TCHAR* argv[])
    {
    	srand((unsigned int) time (0));
    	int a = 1+(rand() % 20); // a is a random number between 1 and 20
    
    	int arr[a]; // declaring array of random size
    	
    	for (int b=0; b<a; b++) // declaring random elements
    	{
    		arr[b] = 1+(rand() % 100);
    	}
    
    
    	int tot =  sizeof( arr ) / sizeof( int ); // getting length of array
    	cout << tot;
    }
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,844
    Rep Power
    1960
    It will be easier to help if you post the error message.

IMN logo majestic logo threadwatch logo seochat tools logo