|
|
| http://www.cplusplus.com/articles/z13hAqkS/ |
array is a bad name for a variable.
|
|
How many integers will you sort? 10 Enter number 1: 1 Enter number 2: 2 Choose order: [1]Ascending or [2]Descending 2 Numbers in Descending: 2 Total sum: 2 |
How many integers will you sort? 5 Enter number 1: 2 Enter number 2: 8 Enter number 3: 6 Enter number 4: 4 Enter number 5: 23 Enter number 6: 25 Enter number 7: 84 Enter number 8: |
| How many integers will you sort? 7 Enter number 1: 2 Enter number 2: 4 Enter number 3: 3 Enter number 4: 5 Choose order: [1]Ascending or [2]Descending 1 Numbers in Ascending: 1 2 Total sum: 3 Invalid Order! |
|
|
How many integers will you sort? 5 Enter number 1: 1 Enter number 2: 2 Enter number 3: 3 Enter number 4: 4 Enter number 5: 5 Choose order: [1]Ascending or [2]Descending 2 Numbers in Descending: 5 4 3 2 1 Total sum: 15 Exit code: 0 (normal program termination) |
| int * array = new int[limit]; |
|
|
| int * array = new int[limit]; |
| http://www.cplusplus.com/reference/new/operator%20new%5B%5D/ |
std::array allows one to use a variable to set the size of the array initially, it can't be changed afterwards.delete[] to go with the new in your code, after you have finished with the variable, otherwise you will be leaking memory. delete[] is for arrays, delete is for ordinary variables.std::vector so you won't have worry about any of that.new and delete isn't really recommended (although there is no harm with it here), instead check out smart pointers as in std::unique_ptrdelete is not called, such as when an exception is thrown, thereby still leaking memory.| The reason for this is due to situations where delete is not called, such as when an exception is thrown, thereby still leaking memory. |
| And such as when I forget, Gulp. |
| Enter number 1: Invalid! Please try again. |
|
|
|
|