T Minus loops

(while)

T minus 10 and counting
T minus 9 and counting
T minus 8 and counting
T minus 7 and counting
T minus 6 and counting
T minus 5 and counting
T minus 4 and counting
T minus 3 and counting
T minus 2 and counting
T minus 1 and counting

Declare the following index before the while loop:

int index = 10;

Correctly code a while statement below using the variable index as defined above, to produce the output shown above.


So this is what my code looks like...can anyone give me a hint about what I'm missing..?? I also have to convert this same loop into a do while and for loop. So if I can get this one right I think the others should come relatively easy.
Thanks Everyone...! (:

1
2
3
4
5
while (int index >= 10)
      {
         cout << "T minus " << index;
         index--;
      }
Declare the following index before the while loop:
int index = 10;
Correctly code a while statement below using the variable index as defined above,

pay attention to the emphasized words.
it should also be while it is greater than 0. Otherwise it will only do 10 and 9.

I would just use a for loop though.

1
2
3
4
for(int i = 10; i > 0; --i)
{
    std::cout << "T minus " << i << " and counting" << std::endl;
}
thanks giblit but can I use this same format in a while loop...?? or how do they differ really...? Cuz my professor wants me to write both versions of it..
You can do what you just had, though slightly different (as @ne555 suggested):
1
2
3
4
int index = 10;
while (index) { // same thing
    std::cout << "T minus " << index-- << " and counting\n";
}

Though, really should be using index > 0, but just showing that this does work.
Topic archived. No new replies allowed.