nested for loop not working

I am nesting a for loop inside a for loop but the inner loop is not executing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {

    int noOfMissiles, countDown;

    cout << "Enter the number of missiles to launch" << endl;
    cin >> noOfMissiles;

    cout << "Enter the numbers to countdown" << endl;
    cin >> countDown;

    for (int initial = 1; initial <= noOfMissiles; ++initial) {
        cout << "\nMissile number " << initial << " is launching! Countdown is starting..." << endl;
        system("pause");

        for (int number = countDown; number <= 0; --number) {
            cout << "\n" << number << ", ";
        }

        cout << "launch" << endl;

    }

    system("pause");

    return 0;
}
Look at the condition of the inner for loop more carefully.
Hi @mrxib,
try for (int number = countDown; number >= 0; --number)
for (int number = countDown; number >= 0; --number)

It will be decrementing the number which can be equal to 0 or any negative numbers possible. It should be bigger* than 0 so it can decrement till zero.

By looking at the loop, it doesn't make sense to decrement a number that is equal to or smaller than zero.
Last edited on
I am such a dumb. Thanks everyone.
Topic archived. No new replies allowed.