Here's my code.
int main ()
{
int input;
cout <<"Enter a sequence of numbers (0 to quit): ";
cin >> x;
if (x != 0)
{
if (x % 2 == 0)
{
cout << x << " is even" << endl;
}
else if (x % 2 != 0)
{
cout << x << " isn't even" << endl;
}
}
}
Your almost there :
1) change : int input; TO int x;
2) Wrap your code in a do while loop.
int x = -1;
do
{
/* get user input and check for even/oddity */
}while(x != 0) //quits if user enters 0
Reputation Points: 840
Solved Threads: 594
Senior Poster
Offline 3,864 posts
since Dec 2008