0

Using the code below I need to implement it such that p_poly has only one term of any degree and contains no terms with zero coefficients. I have tried to implement a temporary variable to no avail and was wondering if anyone else had an idea or possibly lead me to a solution.

status read_poly(polynomial * const p_poly)
{
  int coef;
  int degree;

  if (init_list(p_poly) == ERROR) {
    return ERROR;
  }

  do {
    printf("\tEnter coefficient, degree (0,0 when done): ");
    scanf(" %d,%d", &coef, ┬░ree);

    if (coef != 0 && term_insert(p_poly, coef, degree) == ERROR) {
      return ERROR;
    }}
   while (coef != 0 || degree != 0);

  return OK;
}
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by Delnith
0

Your scanf should be scanf("%d,%d", &coef, &degree)

There is a logical error with your while loop condition. You say you want non-zero coefficients and any degree, but exit if both are zero?

Correction:
while (coef == 0 || !(coef == 0 && degree == 0));

If coef == 0 just loop again.
If coef == 0 and degree == 0 then exit while loop. But you want to loop if that is not true, so just negate it with !.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.