While Conditions

I'm trying to work through a program and I got it to work, but I'm wondering if there is a cleaner way to write what I'm trying to do. I need to get 2 numbers, run them through an equation and display the answer. The program needs to do this until one of the numbers are 0. Here is what my while loop looks like:

1
2
3
4
5
6
      while ((cin >> x >> y) && ((x != 0) && (y != 0)))
    {
        cout << hm(x, y);
        cout << " is the answer.\n";
        cout << "Enter the next two numbers (q to quit): ";
    }


This worked exactly like I wanted it to, but I was wondering if there is a cleaner way to write this condition? I just don't want to get into bad habits before I move onto more difficult stuff. I would appreciate any feedback.
1
2
while ((cin >> x >> y) && ((x != 0) && (y != 0)))
while ((cin >> x >> y) && x && y)
egg management fee wrote:
I just don't want to get into bad habits before I move onto more difficult stuff. I would appreciate any feedback.
Your current way is already a better habit than my suggested 'cleaner' way ;)
Last edited on
Thank you very much for your feedback!
Topic archived. No new replies allowed.