I am very naive at programming...n very new to it too..pls helpwith the following problem:

#include <iostream>
using namespace std;

int main()
{
    int side;

    cout << "Enter a number: ";
    cin >> side;

    for (int i = 0; i < side; i++)
    {

        int j = 0;
    while (j <= i)
    {
        j++;
        cout << '#';
    }
    cout << "\n";
    }
}

i need to convert this to a do while loop n i did this:

#include <iostream>
using namespace std;

int main()
{
       int side;

       cout << "Enter a number: ";
       cin >> side;

       int i = 0;
       int j = 0;
       do

       {    
          i++;
          while (j <= i)
          {
                  j++;      
                  cout << '#';
          }
            cout << "\n";

        }
        while (i<side);
              cout << '#';
}

but it is not working...i dont kno what is wrong!

Please read the sticky threads about how to ask questions.
Mainly, please put your code inside code tags so it will be more readable, like

[code]

your code goes here

[/code]
Big problem with your second sample is that you must reset j back to 0 after its while loop has concluded. I would also move the i++ to occur after that loop, so that you will get a single symbol output on the first line.

what is your program supposed to do?

#include <iostream>
using namespace std;

int main()
{
int side[255];

cout << "Enter a number: ";
cin >> side;

for (int i = 0; i < side; i++)
{

int j = 0;
while (j <= i)
{
j++;
cout << '#';
}
cout << "\n";
}
}

try that!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.