How do I convert nest for statement to while statement?

#include <iostream>

using namespace std;

int main()

{

const int SCR_SIZE = 22;

int step_number,

x_count;

for (step_number = 1; step_number <= SCR_SIZE; ++step_number)

{

cout << endl;

for (x_count = 1; x_count <= step_number; ++x_count)

cout << "X";

}

cout << endl;

return 0;

}

Update:

error message: Run-Time Check Failure #3 - The variable 'x_count' is being used without being defined.

1 Answer

Relevance
  • Anonymous
    1 decade ago
    Best Answer

    #include <iostream>

    using namespace std;

    int main()

    {

    const int SCR_SIZE=22;

    int step_number = 1;

    int x_count = 1;

    while(step_number<=SCR_SIZE)

    {

    ++step_number;

    cout << endl;

    while(x_count<=step_number)

    {

    ++x_count;

    cout << "X";

    }

    }

    cout << endl;

    return 0;

    }

    Source(s): this was tested in dev c++. no errors on my side so just copy and paste.
Still have questions? Get your answers by asking now.