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;
}
}
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.