/* * Example of the ``dangling else'' problem * * if (y != 0) * if (x != 0) * quotient = x/y; * else * printf("Error: y is equal to 0\n"); * * Question: which ``if'' does ``else'' belong to? * */ #include int main() { double x, y, quotient; printf("Please input x, y > "); scanf("%lf%lf",&x,&y); if (y != 0.0) { if (x != 0.0) quotient = x/y; else // extra line for info quotient = 0; // extra line for info printf("x/y = %.2f",quotient); // extra line for info } else printf("Error: y is equal to 0\n"); return(0); }