Design Suggestions
If you need some help getting started with this assignment,
perhaps the following ideas will help:
First and foremost, DO NOT attempt to put all the code that writes the pattern
into one function. It is a bad design choice to try to pack a large amount
of detailed code into one function.
Instead divide up the work to be done and assign different parts of the work
to different functions.
You could write a function
void makeTileRow (int tr_width)
that is called with a width parameter (tr_width),
and writes pieces of the pattern like this:
||&&&&||*||&&&&||*||&&&&||*||&&&&||*||&&&&||
||&&&&||*||&&&&||*||&&&&||*||&&&&||*||&&&&||
||&&&&||*||&&&&||*||&&&&||*||&&&&||*||&&&&||
||&&&&||*||&&&&||*||&&&&||*||&&&&||*||&&&&||
For example, if the value of the variable width is 3, the call
makeTileRow (width) ;
would write this to the screen:
||&&&&||*||&&&&||*||&&&&||
||&&&&||*||&&&&||*||&&&&||
||&&&&||*||&&&&||*||&&&&||
||&&&&||*||&&&&||*||&&&&||
The output above is part of what the program has to write
when the pattern is required to be three tiles wide.
Also, you could write a function
void makeHorizBorder (int hb_width)
that inputs a width and writes the necessary sequence of equal
signs for a pattern of the indicated width.
For example, if the value of the variable width is 3, the call
makeHorizBorder (width) ;
writes this out:
==========================
As one example of how the program might use these functions in combination,
note that, if width is equal to 3, the sequence of calls:
makeHorizBorder (width) ;
makeTileRow (width) ;
makeHorizBorder (width) ;
writes out one row of tiles 3 tiles wide:
==========================
||&&&&||*||&&&&||*||&&&&||
||&&&&||*||&&&&||*||&&&&||
||&&&&||*||&&&&||*||&&&&||
||&&&&||*||&&&&||*||&&&&||
==========================
Each of the functions described above should use a loop to
write the correct amount of output, based on the value of
the parameter -- the width.
Your program needs to be able to write patterns with
multiple rows of tiles, according to the length input by the user.
For that, you will need to have other looping code in your program
that calls makeHorizBorder(width) and makeTileRow(width)
enough times and in the correct order.
WATCH OUT FOR FENCE POSTS
There are fence-post problems for you to solve when you write
functions like makeHorizBorder and makeTileRow.
Also another fence post problem comes up when you write the
loop that outputs the tile pattern. For example, it takes three
calls to makeHorizBorder and two calls to makeTileRow to
make a pattern with two horizontal rows of tiles.
Keep in mind that it may turn out to be worthwhile if you design
functions like makeHorizBorder and/or makeTileRow to call upon other
functions. For example, you could have a separate function
that makes lines like this:
||&&&&||*||&&&&||*||&&&&||*||&&&&||*||&&&&||
and your makeTileRow could call that function. Similarly you could
have separate functions to make individual small pieces of the
pattern like these pieces: ||, *, &&&&, =,
==, and ====.