Hello Deadweight77,
To start with I would move line 42 to between lines 4 and 5 and change the variable name to all caps. Most often I have seen it written this way:
1 2 3 4 5 6 7 8 9
|
#include <iostream>
#include <ctime>
//using namespace std; // <--- Best not to use.
// A recent post that is worth reading. http://www.cplusplus.com/forum/beginner/258335/
constexpr size_t MAXELEMENTS{ 50 };
void swap(int& val1, int& val2);
|
From C++11 on you can use "constexpr" and the {}s, (the "=" is not needed), or you can just use "const" and what you have. I used "size_t", AKA "unsigned int", because its use needs to be a positive number. Negative numbers are not allowed.
Also when defining a variable as a constant capital letters are the generally accepted way for this.
In "main" you defined line 51 correctly, for the most part, so why did you get line 49 wrong. What you want is
int arr[MAXELEMENTS]{};
. The empty {}s will initialize the array to all (0) zeros.
In the if statement use
return 1;
and use
exit (1);
when it is not in "main".
in the for loop. The use of line is kind of print out the array, but you are really printing out what you entered. Line 65 and 66 almost line up, but do you see any difference between them? Look close at what you enter into and what you are trying to print.
I added these for loops, at least to give you an idea and to show you what you have.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// Print out the arrays
std::cout << "\n Contents of \"arr\"\n ";
for (size_t index = 0; index < size; index++)
{
std::cout << arr[index] << (index < size - 1 ? ", " : "\n");
}
std::cout << "\n Contents of \"num\"\n ";
for (size_t index = 0; index < size; index++)
{
std::cout << num[index] << (index < size - 1 ? ", " : "\n");
}
|
At the end of "main" I use this to pause the program. This is optional.
1 2 3 4 5 6 7
|
// A fair C++ replacement for "system("pause")". Or a way to pause the program.
// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue: ";
std::cin.get();
return 0;
|
The "return 0;" is also optional, but sometimes makes for a good break point when debugging.
Hope that helps,
Andy