How to handle two counter variables in a for loop

The output is showing some garbage values! :/

1
2
3
4
5
6
7
8
9
10
11
12
  #include <iostream>
using namespace std;

int main()
{
    for (int y=0, z=20; y!=z; y++, z--)
    {
        cout << y << " and " << z;}
        system ("pause");
        return 0;
}
    
The values are fine, you just have no spacing so it looks incorrect. Try putting a '\n' after you output z and check the results again.
closed account (48T7M4Gy)
The output might be a bit clearer and make sense if you put an << endl; at the end of line 8

Makes sense to me :-)
:p Yes, you are right!Thanks
Topic archived. No new replies allowed.