my while loop doesn't stop

i'm writing a program that classifies positive integers as odd or even but when I type a number the loop doesn't stop. It will say even or odd depending on the number but it won't stop.

#include <iostream>
using namespace std;

int main ()

int x;

cin >> x;

while (x > 0){

if ((x & 1) == 0){
cout << "EVEN" << endl;

else {
cout << "ODD" << endl;


return x;

x doesn't change within the while loop, so the loop either doesn't run at all (if x>0 is false) or it runs forever (if x>0 is true). To fix this, I'd change x to be unsigned instead of int so the compile can enforce the requirement that values be non-negative. Then move the cin >> x inside the while loop:
while (cin >> x) {
Topic archived. No new replies allowed.