Hmm, I had the curly braces in there in my program, I must have copied a bit of old code. In any case, I put the numComps incrementor in right before the if statement and it's returning 12497500 comparisons. That seems a little high to me considering that there are only 5000 numbers in the array. This definitely looks like a step more in the right direction than what I had before, though.
NEW QUESTION (that should be easier to answer):
Below are three functions, each for a different sorting method (bubble, selection and insertion). You'll notice two unused int variables numComps and numAssigns that are both initialized to 0. What I need to do is to have numComps increase by one for every comparison made and numAssigns increase by one for each assignment made. Then I need to output the results. I know how to increase them by one with numComps++ and numAssigns++ and then output it with cout << numComps << " ::: " << numAssigns; at the end of the loops, however I'm having a hard time figuring out where to put numComps++ and numAssigns++. It seems like wherever I do it just goes to the max number of items in the array or sits at one. Any help?Spoiler
Well, firstly, that second for loop in bubble sort needs to have curly braces around what it's looping. Regardless of how many statements are being looped, they should always be wrapped by curly braces, even it it's just one statement. Same goes for if additional lines under if statements. ANYWAY, that being said, for bubble sort, since you need to check the number of comparisons, then you need to increment it right before that if statement, hence the need for curly braces to wrap that second for loop. On the phone, so it's a bitch to type, will look at the others later.
edit: okay, here's the whole program. I'm supposed to make three arrays with 5000 identical random numbers (I am aware that the random numbers that get generated are the same random numbers every time with just the rand() function, but that's okay for this), so I create one array and populate it with random ints and then copy each index into the other arrays. Got that part no problem. Then I need to output the number of comparison and assignments that are made in each sorting method to see which ones perform more/less. The output at the end of the bubbleSort function is just a placeholder for how the output should look without polishing and it needs to go into the other functions as well. Like I said before, my problem is that I'm not sure where to put the incrementors for the numComps and numAssigns variables to get the right numbers.