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

Recommended Answers

All 2 Replies

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 !.

solved it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.