While loop issue

Can someone tell me why my while loop on my homework only runs once?

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
  #include <iostream>
#include <iomanip>
using namespace std;

int main(){
	
	int a, aa, b, c, d, x = 0;

	cout << "Enter four numbers: ";
	cin >> a >> b >> c >> d;
	
	cout << endl;
	
	while(a != b && a != c && a != d ){
		aa = a;
		a -= b;
		b -= c;
		c -= d;
		d -= aa;
		x++;
		
		if(a < 0)
			a *= -1;
		
		
		if(b < 0)
			b *= -1;
		
		
		if(c < 0)
			c *= -1;
			
		if(d < 0)
			d *= -1;
		
	}
	
	cout << "This group converges to value " << a << " after " << x << " steps.";
}
griffingradke wrote:
Can someone tell me why my while loop on my homework only runs once?

Because you are a naughty boy and double posting.
http://www.cplusplus.com/forum/beginner/243644/#msg1079972


Change line 14 to
while(a != b || a != c || a != d ){

Otherwise, any one of the others being equal to a will stop the loop.
Last edited on
lmao naughty me thank you for your help.
Topic archived. No new replies allowed.