#include <iostream>
usingnamespace std;
int main()
{
int index, amountInput; // The user's number and amount values
// Get the amount of spaces to hold for the player's allocated numbers
cout << "How many numbers would you like to enter? : ";
cin >> amountInput;
int* allocatedStorage = new (nothrow) int [amountInput]; // Allocates enough space in memory for the amount entered
// If the computer cannot allocate enough memory handle it
if (allocatedStorage == NULL)
{
cout << "Cannot allocate enough memory!" << endl;
return 0;
}
// Loop through the indexes of the allocated space for the user to place values for
for (index = 0; index < amountInput; ++index)
{
cout << "Enter number: ";
cin >> allocatedStorage[index];
}
cout << "Your number's are : ";
// Print the values of all the storage space in the allocated reference
for (index = 0; index < amountInput; ++index)
{
cout << allocatedStorage[index] << " ";
}
delete[] allocatedStorage; // Free the allocated memory after we are done with it so other processes can use it
cout << endl;
return 0;
}
Thank you for viewing my thread! Very appreciated.