0

Only getting ***** of following code instead of getting right triangle of *..kindly debug it

#include <iostream> using namespace std; int main() { int i,j; j=1; i=1; do { cout<<"*"; i++; } while(i<=5); do { j=1; cout<<"\n"; j++; } while(j<=i); return 0; }

13th Dec 2018, 11:04 AM
Usman Zafar
Usman Zafar - avatar
4 Réponses
+ 4
You have two separate loops, instead of a nested loop (loop within a loop). Did you try putting the second loop within the first loop? Can you do it? :>
13th Dec 2018, 11:23 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Hey! You have to encapsulate the inner do while loop inside the outer loop, then print new line in the outer and the * in the inner and increment the j in the outer loop not in the inner!
13th Dec 2018, 11:29 AM
Sekiro
Sekiro - avatar
+ 1
Solved my prob... Thanks for everyone for helping.. Below is final working code //////////////////////////////////////// #include <iostream> using namespace std; int main() { int i=1; do { int j=1; do { cout<<"*"; j++; } while(j<=i); cout<<"\n"; i++; } while (i<=5); cout<<"\n"; return 0; }
16th Dec 2018, 5:06 AM
Usman Zafar
Usman Zafar - avatar
- 1
No i cant nested two loops as me totaly new to loop... Kindly make changes in code
13th Dec 2018, 12:16 PM
Usman Zafar
Usman Zafar - avatar