how to convert this to while loop

hi , i currently new to c++ was wondering how to convert the lower portion using nested while-loop. can someone please help me with this. thanks

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
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;

int main ()
{
	int n, i, j, l;
	
	// Read in a postive number with data validation
	do
	{
		cout << "Enter an interger less 10: ";
		cin >> n;
	}while (n < 0 || n >= 10);
	
	
       do
       {
	  for (l = 1; l <= n; l++)
		{   for (i = 1; i <= l; i++)
			{
				for (j = 1; j <= i; j++)
				
				cout << "*" << " ";
		 	 	cout <<endl;
			
			}
			
			int i = 1;
			
			while (i <= l)
			{
				for (j = 1; j <= i; ++j)
					cout << "&" << " ";
		 	 		cout <<endl;
					i++;
			}
		
		}
		
		
	}while (l < n);
		
}

Last edited on
please use code tags please..
Last edited on
sorry about that.
try this one..
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
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;

int main ()
{
    int n;

    // Read in a postive number with data validation
    do{
       cout << "Enter an interger less 10: ";
       cin >> n;
    }while (n < 0 || n >= 10);
    
    int l=1;
    while(l<=n){
            int i=1;
            while(i<=l){
                int j=1;
                while(j<=i){
                    cout<<"* ";
                    j++;
                }
                i++;
                cout<<endl;
            }   
            
            i=1;
            while(i<=l){
                int j=1;
                while(j<=i){
                    cout<<"& ";
                    j++;
                }
                i++;
                cout<<endl;
            }   
         l++;  
    }   
    system("pause");
}
that's better that you have indentions. it's a good practice keep it up dude..
what if i just want to convert this portion.
1
2
3
4
5
6
7
8
9
			int i = 1;
			
			while (i <= l)
			{
				for (j = 1; j <= i; ++j)
					cout << "&" << " ";
		 	 		cout <<endl;
					i++;
			}



cause the upper portion i need to use for loop. sorry just now my qns was unclear.
the ++j is to make it display as square.
Last edited on
replace that portion with this one
1
2
3
4
5
6
7
8
9
10
          int  i=1;
            while(i<=l){
                int j=1;
                while(j<=i){
                    cout<<"& ";
                    j++;
                }
                i++;
                cout<<endl;
            }   
Last edited on
got to go hope that help you.. LOL im also a newbie
hmm it give me both triangles.
ahh thanks psychoder i just change the valubles abit and it solve. thanks dude.
Topic archived. No new replies allowed.