Having trouble with 2D array
Dec 3, 2012 at 12:45am UTC
I'm very new at C++ and for an assignment i am supposed to create this 2D array display using a loop.
Pattern A
+
++
+++
++++
+++++
++++++
+++++++
++++++++
+++++++++
+++++++++++
So far this is what I have. Can I use this nested for loop to increment the amount of '+' from 1? If yes, can someone help me along?
Thank you any help is much appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
using namespace std;
int main()
{ cout << " Pattern A " << "\t\t" << " Pattern B" << endl;
cout << "________________________________________" << endl;
for (int row = 0; row < 10; row++)
{
for (int add = 0; add < 10; add ++)
{
cout << '+' ;
if (add == 10 )
break ;
}
cout << endl;
}
return 0;
}
Dec 3, 2012 at 1:00am UTC
Your logic is flawed. It should be something along the lines of:
Currently, it says:
1 2
for row 1 to 10
output '+' 10 times
Should be:
1 2
for row 1 to 10
output '+' row times
Topic archived. No new replies allowed.