Polynomial

Im having trouble getting my program to rerun an insert function.

1
2
3
4
5
6
7
8
cout << "Enter the coefficient and power of a term (0, 0 to stop): ";
	cin >> c >> power;
	while (c != 0 && power != 0)
	{
		p.insert(c, power);
		cout << "Enter the coefficient and power of a term (0, 0 to stop): ";
		cin >> c >> power;
	}


When I enter one 0, for example (-3, 0), it exits the while loop and doesn't include those inputs for the function. Why?
Your condition is NOT C AND NOT P. (where C means c == 0 and P means power == 0)
By DeMorgan's law this is the same as NOT(C OR P)
which translates into your code as:

while ( ! (c == 0 || power == 0) )

"while it's not the case that c or power is 0"
But you really want "while it's not the case that c and power are both 0"

while (!(c == 0 && power == 0))

We can translate that back (deMorgan again)

while ( c ! = 0 || power ! = 0)
Last edited on
Topic archived. No new replies allowed.