user input to determine array size

Hello,

sorry for any unorganization this is my first post, here is my prompt:

For this lab, you need to develop a C++ program that prompts the user for a number of integers, and that
determines the 2 smallest numbers, as well as the 2 largest numbers.

Your program should make use of an array of a size determined after the user enters the number of
integers that will be held in the array. The number of integers should be at least 2 to guarantee that there
will be a next smallest and a next largest.
Once the input is complete, your program should determine the 2 smallest and the 2 largest numbers held
in the array
Rather than use 4 separate loops to determine each of these separate statistics, your implementation
should only use one single loop for that purpose. (Note that, completely separately, there should be
another loop to enter the numbers in the first place.)
Your implementation cannot sort the numbers.


I have most of the code completed, but i can't figure out how to set the size of the array to the integer the user inputs. any pointers in the right direction would be much appreciated. thanks
You need to use the new operator which allocates it on the heap. Make sure to delete[] it after you've done using it, or it may result in a memory leak.

http://www.cplusplus.com/reference/new/operator%20new[]/
Last edited on
Topic archived. No new replies allowed.