Nestedloops


So I have to write a nested loop with asteriks and forward and backslashes.

[//Write a program with for nested loops

//Faizan Khan
//04/24/21

#include <iostream>
using namespace std;

int main ()
{
int i;
int j;
int k;
int n;

for (i = 0; i < 7; i++)
{
for (n = i; n < 6; n++)
{
cout << "*";
}
for(n = 0; n < i+2; n++){
cout<<" ";
}
cout<<" ";
for (j = i; j < 13; j++)
{
cout << "/";
}
if(i != 0)
{
for(k = 0; k< i+1; k++){
cout << "\\";
}
}
else
cout<<" ";
for(n = 0; n < i+2; n++){
cout<<" ";
}
for (n = i; n < 6; n++)
{
cout << "*";
}

cout<<endl;
}

system("PAUSE");
return 0;
}
]
The problem I am having is with the middle block. The middle block is to be 12 columns where I have to transition to forward slashes to the first row to all black slashes in the seventh row. In the second row I have to replace two forward slashes with two backslashes from right end to left end so that the seventh row will have all backslashes
Last edited on
How do I input a pdf because it has the output
Hello faizankhan40,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.


You can copy the contents and paste it between output tags.

"i", "j", "k" and "n" should be defined in the for loops, unless you need them outside the for loops, which you do not.

Andy
Topic archived. No new replies allowed.