*^*^*^*^*^*^ <---- 1st time through your first for loop
*^*^*^*^*^ <---- 2nd time through your first for loop
*^*^*^*^ <---- 3rd time through your first for loop
*^*^*^ ect. ect.
*^*^
^^
| |
| Second pass through your second for loop
|
1st pass through your second for loop
So we are basically generating the "rows" with the first for loop, and the "columns" with the second for loop. So we need to look in the second loop to alternate between '*' and '^'.
Now what would happen if you added the '^' symbol into the cout statement after the '*' symbol?
Test that out and then I think you should be able to figure out the rest :)
Please don't just give the person the answers it teaches them absolutely nothing and doesn't help them learn what was the problem. Specially when you don't even explain what you did and just post code and that is it.
// Note that the pattern is assumed to have 2 characters
// as in it points to a char [2] and they've been initialised
void patternAsc(int n, char *pattern)
{
for (int i = 1; i < n; ++i)
{
for (int j = 0; j < i; ++j)
{
cout << pattern[0] << pattern[1];
}
cout << endl;
}
}
int main(void)
{
char ch[2] {'*', '^',};
patternAsc(10, ch);
cout << endl;
return 0;
}
You can use that to figure out how you want it exactly...so not really giving away the whole answer..
You can include another function parameter to indicate the size of the pattern and then can add more patterns in the main function.
Really am not trying to pick a fight it just annoys me when people just post the answer to a problem without even letting the person who asked the question figure it out on their own.
I was also just pointing out that this statement
Contrary to what Zereo said, don't alternate between * and ^. Instead, treat them as pairs.
was false and that was not what I was suggesting.
So again not trying to pick a fight with you and sorry if you thought I was just letting you know in the future I would suggest against just posting the answer to questions on the forum because it teaches the person absolutely nothing and just hurts them in the long run.
I am not responsible for an adult's education in a public forum; I am here to provide solutions. If a college student is not able to peruse my solutions, then they should go back to their book, instructor, TA or tutor.
Moreover, take notice of the poster's question quality.
Many ways to skin a cat. Some of them even involve not having to test for 1, which is a logical error anyways, since true is actually defined as not 0.