while loop

//Print every odd number descending from 39

int y = 0;

while(y <= 39){
cout << y;
y = (y - 2);// Take two from y after every loop
}
How do I stop the loop
Last edited on
You're initializing y to 0, but it looks like you want to initialize to 39 and then count down from there in the loop, stopping when you reach 0. So while y is greater than 0, you want to keep running the loop.

Topic archived. No new replies allowed.