When the cin extracts an integer it reads until a non-integral value. In this case, it is the "-". So if you type 123456-1, num[0] = 123456 and num[1] = -1. The loop is waiting for you to enter in 98 more integers.
Your loops are still a little loopy. You enter the first loop, type in a number, enter the second loop (and if the number you typed is less than 100), start looping through junk data in your array. Your mode is going to come out garbage, then most likely enter another loop that will never end. If it didn't , then you still loop through j until the number you originally entered reaches 100. Do that 99 more times and your program is done.
This is why I recommend breaking your code into pieces.
Piece 1, which is already trouble because the way cin works could be something like:
1 2 3 4 5 6
|
const int SIZE = 100;
int num[SIZE], i = 0;
for (; i << SIZE && num[i] != -1; i++){
cout << "Enter a number (-1 to end): ";
cin >> num[i]; cin.ignore(80, '\n');
}
|
This is going to be more hitting enter than you originally planned. You're going to have to do "1" "Enter" "2" "Enter" "-1" "Enter".
Another thing would be to make a character array:
1 2 3 4
|
const int SIZE = 100;
char num[SIZE];
cout << "Enter your numbers. (-1 to stop)";
getline(cin, SIZE, '-');
|
Which is a terrible idea if you want numbers greater than 9.
With that you could enter: 12345-1 (even just 12345-) and you will fill your array. I don't know if this will null terminate the array, so you will have to figure that out, and then the amount of things that the person entered.
Then you can move to step 2, sort and find the mode. This should be a completely separate loop. Since characters are numbers, you will still be able to use the same sorting/finding methods.
When that loop is done, then
cout << "Your mode is: " << mode