I received this assignment and I spent the last hour trying to figure it out but I don't seem to know how to do it. I have tried many ideas but none of them worked. Here is the expected output:
This is my final version of the code. It works however for some reason it doubles the number of columns. I'm not sure how to fix it.
int rows;
int columns;
int k = 0;
int j;
int i;
string pattern1;
string pattern2;
cout << "Enter number of desired rows: ";
cin >> rows;
cout << "Enter number of desired columns: ";
cin >> columns;
pattern1 = " \\@/";
pattern2 = " /*\\";
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= columns; j++)
{
if (i % 2 == 0)
{
cout << " /@\\";
}
else
cout << pattern1;
if (k == 0)
{
if (i % 2 == 0)
{
cout << " \\*/";
}
else
cout << pattern2;
}
} cout << endl;
}
Aucun commentaire:
Enregistrer un commentaire