stuck in a loop please help

So I'm writing a program in C++ and for this function I am reading in the coefficient and exponent of terms in the polynomial. It compiles, but it never stops reading in values. I comiled it with warnings and got the warning "contrl reaches end of non-void function. It is supposed to stop reading values in once and exponent of 0 is read in. Thank you in advance!
Poly read_poly(const int label)
{
// Replace with your code
Poly poly; //polynomial being read in
int coeff; //coefficient
int exp; //exponent
bool finish = false; //checks whether the user is done inputting values
bool check = false; //checks to make sure terms are valid
while (!finish){
cin>> coeff;
cin>> exp;
if((!check) && (exp>0) && (coeff != 0)){
check = true;
}
if (exp < 0 && exp > check){
cout<< "Invalid term. Bye!";
exit(EXIT_FAILURE);
}
while (coeff == 0 && exp != 0){
cin.ignore(10);
cin>> coeff;
cin>> exp;
}
poly.addTerm(coeff, exp);
if (exp == 0){
finish = true;
}
}

}
¿what's your input?

1
2
3
4
5
		while(coeff == 0 && exp != 0) {
			cin.ignore(10); //explain the purpose of this
			cin >> coeff;
			cin >> exp;
		}


1
2
3
4
		if(exp < 0 && exp > check) {
			cout << "Invalid term. Bye!";
			exit(EXIT_FAILURE);
		}
first, `check' is a boolean. Its value may be true or false, ¿what's the purpose of doing a greater than comparison?
second, ¿what value may have `exp' for that condition to be successful?

> got the warning "contrl reaches end of non-void function
which you proceed to ignore.
the purpose of your function is to read a polynomial, so it should return a polynomial.
Last edited on
Topic archived. No new replies allowed.