int arraySize = 0;
//some code
std::cout << "enter number of elements" << std::endl;
std::cin >> arraySize;
//declare and define array
//read each elem using loop for arraySize - 1 times
int arraySize = 0;
cout<<"Enter array size"<<endl; //prompts user for number of workers
cin>>arraySize; //number of workers
int arrayElement[arraySize]; //declairs the array with the input size
cout<<"Enter array value"<<endl; //prompts user for value in the array
for (i=0;i<arraySize;i++) //loops the array from 0 to < arraySize for value of array
{
cin>>arrayElement[i];}
#include <iostream>
#include <new>
usingnamespace std;
int main ()
{
int i,n;
int * p;
cout << "How many numbers would you like to type? ";
cin >> i;
p= new (nothrow) int[i];
if (p == 0)
cout << "Error: memory could not be allocated";
else
{
for (n=0; n<i; n++)
{
cout << "Enter number: ";
cin >> p[n];
}
cout << "You have entered: ";
for (n=0; n<i; n++)
cout << p[n] << ", ";
delete[] p;
}
return 0;
}
Variable sized arrays are not kosher C++ -- they're a C99 feature that GCC's compiler allows you to use if you don't ask it to enforce ANSI compliance.