PDA

View Full Version : Creating a pattern using void ()


SteveDawg85
03-01-2006, 10:49 PM
My professor assigned us a project to create a specific type of pattern using some of the following traits:
it will ask the user for the # of lines to be displayed
it will ask the user for the character to be displayed
It will start from the top right and slowly be decrease by one

Ex.
5 lines and using *
*
**
***
****
*****

(actually, the above is supposed to start from the top right and work its way down. so just 'mirror' the image)

Something similar to this. so far I have this but I am not sure if i am going down the right track

void patter (void)
{
char ch;
int lines;
//Then I am pertty sure i have to use nested loops by I'm not too familiar with what to insert in them. I know i have to use setw() and also the for loops.
}

Any help would be appreciated!!
thanks
-Steve

Melon00
03-06-2006, 03:03 PM
I would use double for loops to solve that problem. Here is C++ code I would use,

int nLines = 0;
char cInput = '.';

//prompt and get input from user here

char output[nLines][nLines]; // this will be used to print to screen

for (int j=nLines; j > 0; j--)
for (int i=0; i < j; i++)

output[i][j] = cInput;

//print to screen
for (int j=nLines; j > 0; j++)
{
for (int i=0; i < j; i++) cout << output[i][j];
cout << endl;
}

I think this will work, but havent compiled and run it. If it is backwards, you may need to switch stuff in the for loops around. Let me know if you run into any more problems