Help: nested while loop pattern

.




Last edited on
Hmmm...

I think you need to try a little bit harder!

Writing to the console (i.e. using std::cout)

Solve this problem first (with just a single loop)

OOOOO

then work out how to do (just)

XOOOO

and (just) this

OXOOO

and then add a second loop.

and then modify the code to write to a file.

(See Iteration statements (loops) / The while loop section here:
Statements and flow control
http://www.cplusplus.com/doc/tutorial/control/

and also:
Input/output with files
http://www.cplusplus.com/doc/tutorial/files/ )

Andy

PS Could you please use code tags (ideally inc. going back and go back and reformating your earlier post.)

"How to use code tags"
http://www.cplusplus.com/articles/jEywvCM9/

1
2
3
4
5
6
7
8
9
10
// little C++ Shell cog wheel button ---->
// (if missing try refreshing your browser)
#include <iostream>
using namespace std;

int main() {
    cout << "Hello code tags!\n";

    return 0;
}

Last edited on
I figured it out thanks!
Why nuke your post?

Ideally you would have not only left your post but summarised your solution!

Andy
Please, do not delete your posts, it is rude for everyone who helps you and makes it impossible for users having similar problem to find solution themself.
Original post:
krammer1280 wrote:
Hi there.

Could anyone give me a hand to figure out how to do this:


Use a nested while loop to draw the following pattern in row-major sequence and write it to an output file:

XOOOO
OXOOO
OOXOO
OOOXO
OOOOX

I really did my best to figure it out, but couldn't do it.

What I have so far:

#include <iostream>
using namespace std;

int main()
{
int row, col; //row index and column index
}

Topic archived. No new replies allowed.