Issue with int not being modifiable?

So I was working through some extra exercises in the book for my C++ class and was coding up one that had you sort an array using a bubble sort. I had it working and the next exercise had improvements to the algorithm. One of these was making the algorithm check if a pass needed to be done and now I'm getting an error in the while loop (I switched over from a for loop). The error says "left operand must be l-value" and appears to point to the variable "passes" which is declared as an int? Anyway, here's the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>

using namespace std;

void randomize_array(int[], int);
void print_array(const int[], int);

int main()
{
	srand(time(0));

	int passes = 1;
	const int array_size = 100;
	int array_to_sort[array_size] = {};
	int temp_hold_value;
	int decrement_counter = 0;
	bool loop_needed = true;
	
	
	randomize_array(array_to_sort, array_size);
	print_array(array_to_sort, array_size);

	while (passes <= (array_size - 1) && loop_needed = true)
	{
		decrement_counter++;
		loop_needed = false;
		passes++;

		for (int i = 0; i < array_size - decrement_counter; i++)
						
			if (array_to_sort[i] > array_to_sort[i+1])
			{
				temp_hold_value = array_to_sort[i+1];
				array_to_sort[i+1] = array_to_sort[i];
				array_to_sort[i] = temp_hold_value;
				loop_needed = true;
			}

	}

	cout << "\n\nArray after sort:" << endl;
	print_array(array_to_sort, array_size);


	system("pause");
}


The issue is with the line
while (passes <= (array_size - 1) && loop_needed = true)

I appreciate any help. I understand the basics (probably very basics) of l-values, the left side needs to be a modifiable value. Not sure why passes isn't here.

Thanks!
Well, to set you off on the right foot, you're SETTING loop_needed to true in that line instead of CHECKING if it's true.
Wow, ok. I feel stupid.

Thanks! I was so focused on where the error code was pointing (passes) I didn't read the rest of the line any of the million times I looked over it. I get why it affects passes though.

Thanks a ton.
Topic archived. No new replies allowed.