Online Compiler C

#include <iostream> using namespace std; int main() { int num, positive = 0, negative = 0; do { cout << "Enter a number: "; cin >> num; if (num > 0) positive++; else if (num < 0) negative++; } while (num != 0); cout << "Positive numbers are: " << positive << endl; cout << "Negative numbers are: " << negative << endl; return 0; }
This program repeatedly asks the user to enter numbers and counts how many are positive and how many are negative. The loop stops when the user enters 0, and then it prints the counts.

- The loop condition checks `num != 0`, but `num` is only updated inside the loop. Think about what happens if the user enters 0 on the very first input: the loop body runs once, counts 0 as neither positive nor negative, and then the condition `num != 0` is false, so the loop ends. That is correct behavior.

- However, note that the program counts zero as neither positive nor negative, which is fine. But consider: if the user enters 0, the loop ends immediately after that iteration, so zero is not counted in either category. That matches the logic.