Top-down design to display tile pattern

I'm confused about how to fix my parameter declaration errors. I think I have a misunderstanding of what the "for" parameters are stating in void MakePattern(int, int) and void MakeCourse(int). Could someone help me understand my error messages of "courses, a_width, and layer are not declared in the scope". How do I declare them? or do I need to change the names of the variables?

Here's what I have so far:


/*

This program makes displays like the following.

| || |
|++++++++++=""=++++++++++++++||++++++++++=""=++++++++++++++|
|++++++++/ _ _ \++++++++++++||++++++++/ _ _ \++++++++++++|
|+++++++| d b |+++++++++++||+++++++| d b |+++++++++++|
|+++++++\ /\ /+++++++++++||+++++++\ /\ /+++++++++++|
|++++++,/'-=\/=-'\,++++++++++||++++++,/'-=\/=-'\,++++++++++|
|+++++/ / \ \+++++++++||+++++/ / \ \+++++++++|
|++++| / \ |++++++++||++++| / \ |++++++++|
|++++\/ \ / \/++++++++||++++\/ \ / \/++++++++|
|++++++++'. .'++++++++++++||++++++++'. .'++++++++++++|
|jgs+++++_|`~~`|_++++++++++++||jgs+++++_|`~~`|_++++++++++++|
|++++++++/|\ /|\++++++++++++||++++++++/|\ /|\++++++++++++|
| || |
| || |
|++++++++++=""=++++++++++++++||++++++++++=""=++++++++++++++|
|++++++++/ _ _ \++++++++++++||++++++++/ _ _ \++++++++++++|
|+++++++| d b |+++++++++++||+++++++| d b |+++++++++++|
|+++++++\ /\ /+++++++++++||+++++++\ /\ /+++++++++++|
|++++++,/'-=\/=-'\,++++++++++||++++++,/'-=\/=-'\,++++++++++|
|+++++/ / \ \+++++++++||+++++/ / \ \+++++++++|
|++++| / \ |++++++++||++++| / \ |++++++++|
|++++\/ \ / \/++++++++||++++\/ \ / \/++++++++|
|++++++++'. .'++++++++++++||++++++++'. .'++++++++++++|
|jgs+++++_|`~~`|_++++++++++++||jgs+++++_|`~~`|_++++++++++++|
|++++++++/|\ /|\++++++++++++||++++++++/|\ /|\++++++++++++|
| || |
| || |
|++++++++++=""=++++++++++++++||++++++++++=""=++++++++++++++|
|++++++++/ _ _ \++++++++++++||++++++++/ _ _ \++++++++++++|
|+++++++| d b |+++++++++++||+++++++| d b |+++++++++++|
|+++++++\ /\ /+++++++++++||+++++++\ /\ /+++++++++++|
|++++++,/'-=\/=-'\,++++++++++||++++++,/'-=\/=-'\,++++++++++|
|+++++/ / \ \+++++++++||+++++/ / \ \+++++++++|
|++++| / \ |++++++++||++++| / \ |++++++++|
|++++\/ \ / \/++++++++||++++\/ \ / \/++++++++|
|++++++++'. .'++++++++++++||++++++++'. .'++++++++++++|
|jgs+++++_|`~~`|_++++++++++++||jgs+++++_|`~~`|_++++++++++++|
|++++++++/|\ /|\++++++++++++||++++++++/|\ /|\++++++++++++|
| || |

*/

#include <iostream>
using namespace std ;

/* function prototype */
void GetDims (int & width, int & courses) ;
/* Get dimensions from the user */

/* function prototype */
void MakePattern(int the_width, int the_height) ;
/* write a pattern to the screen,
the_width squares wide and the_height squares high. */

/* function prototype */
void MakeCourse (int a_width) ;
/* This function makes one 'course' of a 'square' pattern. The argument
a_width denotes how many squares there are, running from left to right.
(Text) [mysolo5.cpp] "mysolo5.cpp" */

/* function prototype */
void MakeLayer (int layer, int w_width) ;
/* This function repeats one layer of a tile (one line's worth) to
make one layer of a course. For example, a call of MakeLayer(6 , 2)
would make this output:

++++++,/'-=\/=-'\,++++++++++||++++++,/'-=\/=-'\,++++++++++|

because the sixth line in this tile

| |
|++++++++++=""=++++++++++++++|
|++++++++/ _ _ \++++++++++++|
|+++++++| d b |+++++++++++|
|+++++++\ /\ /+++++++++++|
|++++++,/'-=\/=-'\,++++++++++|
|+++++/ / \ \+++++++++|
|++++| / \ |++++++++|
|++++\/ \ / \/++++++++|
|++++++++'. .'++++++++++++|
|jgs+++++_|`~~`|_++++++++++++|
|++++++++/|\ /|\++++++++++++|
| |

looks like this:

|++++++,/'-=\/=-'\,++++++++++|

and that line of the tile has to be repeated 2 times when the width of
the course is 2.

*/

int main (void)
{
int width, courses ;

GetDims (width, courses);

if (width == 0 ||courses == 0)

{
cout << "Dimensions must be positive.\n";
cout << endl;
}
else
{
MakePattern(width, courses);
}

return 0;
}

/* function definition */
void GetDims (int& width, int& courses)
{
cout << "How many tiles wide do you want your floor to be?\n";
cin >> width;
cout << "How many courses do you want in your floor?\n";
cin >> courses;
cout << endl;
}

/* function definition */
void MakePattern(int the_width, int the_courses)
{

for (i=0; i<=courses; i++)
{
MakeCourse(a_width);
}
}

/* function definition */
void MakeCourse (int a_width)
{

for (i=0; i<= 13; i++)
{
MakeLayer(layer, a_width);
}
}

/* function definition */
void MakeLayer (int layer, int a_width)
{

if (layer==1)
{
cout << "| |\n";
}
else if (layer==2)
{
cout << "|++++++++++=""=++++++++++++++|\n";
}
else if (layer==3)
{
cout << "|++++++++/ _ _ \\++++++++++++|\n";
}
else if (layer==4)
{
cout << "|+++++++| d b |+++++++++++|\n";
}
else if (layer==5)
{
cout << "|+++++++\\ /\\ /+++++++++++|\n";
}
else if (layer==6)
{
cout << "|++++++,/'-=\\/=-'\\,++++++++++|\n";
}
else if (layer==7)
{
cout << "|+++++/ / \\ \\+++++++++|\n";
}
else if (layer==8)
{
cout << "|++++| / \\ |++++++++|\n";
}
else if (layer==9)
{
cout << "|++++\\/ \\ / \\/++++++++|\n";
}
else if (layer==10)
{
cout << "|++++++++'. .'++++++++++++|\n";
}
else if (layer==11)
{
cout << "|jgs+++++_|`~~`|_++++++++++++|\n";
}
else if (layer==12)
{
cout << "|++++++++/|\\ /|\\++++++++++++|\n";
}
else if (layer==13)
{
cout << "| |\n";
cout << endl;
}


}



Thanks for your time!
Neema
In your MakePattern function definition, you are trying to pass a non-existent variable named a_width. In your MakeCourse function a_width exists because it is declared in the function arguments, however the same is not true for MakePattern. Did you mean to use the_width instead?

Also, please place your code in /code tags, and use indentations to organize your code in a more reader-friendly format. It is very hard to read when everything is smooshed against the left side of the screen. :)

Thanks,
Thank you for the quick response. I changed the names to match the function arguments. When compiled, the program doesnt return any error messages, but it only runs the function GetDims. After I input values for width and courses, it does not display any tiles. I'm not sure what the disconnect between the functions are. I cant find the error in the logic I have. It seems to make sense.

Any suggestions?

Here's what I have so far:

/*

This program makes displays like the following.

| || |
|++++++++++=""=++++++++++++++||++++++++++=""=++++++++++++++|
|++++++++/ _ _ \++++++++++++||++++++++/ _ _ \++++++++++++|
|+++++++| d b |+++++++++++||+++++++| d b |+++++++++++|
|+++++++\ /\ /+++++++++++||+++++++\ /\ /+++++++++++|
|++++++,/'-=\/=-'\,++++++++++||++++++,/'-=\/=-'\,++++++++++|
|+++++/ / \ \+++++++++||+++++/ / \ \+++++++++|
|++++| / \ |++++++++||++++| / \ |++++++++|
|++++\/ \ / \/++++++++||++++\/ \ / \/++++++++|
|++++++++'. .'++++++++++++||++++++++'. .'++++++++++++|
|jgs+++++_|`~~`|_++++++++++++||jgs+++++_|`~~`|_++++++++++++|
|++++++++/|\ /|\++++++++++++||++++++++/|\ /|\++++++++++++|
| || |
| || |
|++++++++++=""=++++++++++++++||++++++++++=""=++++++++++++++|
|++++++++/ _ _ \++++++++++++||++++++++/ _ _ \++++++++++++|
|+++++++| d b |+++++++++++||+++++++| d b |+++++++++++|
|+++++++\ /\ /+++++++++++||+++++++\ /\ /+++++++++++|
|++++++,/'-=\/=-'\,++++++++++||++++++,/'-=\/=-'\,++++++++++|
|+++++/ / \ \+++++++++||+++++/ / \ \+++++++++|
|++++| / \ |++++++++||++++| / \ |++++++++|
|++++\/ \ / \/++++++++||++++\/ \ / \/++++++++|
|++++++++'. .'++++++++++++||++++++++'. .'++++++++++++|
|jgs+++++_|`~~`|_++++++++++++||jgs+++++_|`~~`|_++++++++++++|
|++++++++/|\ /|\++++++++++++||++++++++/|\ /|\++++++++++++|
| || |
| || |
|++++++++++=""=++++++++++++++||++++++++++=""=++++++++++++++|
|++++++++/ _ _ \++++++++++++||++++++++/ _ _ \++++++++++++|
|+++++++| d b |+++++++++++||+++++++| d b |+++++++++++|
|+++++++\ /\ /+++++++++++||+++++++\ /\ /+++++++++++|
|++++++,/'-=\/=-'\,++++++++++||++++++,/'-=\/=-'\,++++++++++|
|+++++/ / \ \+++++++++||+++++/ / \ \+++++++++|
|++++| / \ |++++++++||++++| / \ |++++++++|
|++++\/ \ / \/++++++++||++++\/ \ / \/++++++++|
|++++++++'. .'++++++++++++||++++++++'. .'++++++++++++|
|jgs+++++_|`~~`|_++++++++++++||jgs+++++_|`~~`|_++++++++++++|
|++++++++/|\ /|\++++++++++++||++++++++/|\ /|\++++++++++++|
| || |

*/

#include <iostream>
using namespace std ;

/* function prototype */
void GetDims (int & width, int & courses) ;
/* Get dimensions from the user */

/* function prototype */
void MakePattern(int the_width, int the_height) ;
/* write a pattern to the screen,
the_width squares wide and the_height squares high. */

/* function prototype */
void MakeCourse (int a_width) ;
/* This function makes one 'course' of a 'square' pattern. The argument
a_width denotes how many squares there are, running from left to right.
*/

/* function prototype */
void MakeLayer (int layer, int w_width) ;
/* This function repeats one layer of a tile (one line's worth) to
make one layer of a course. For example, a call of MakeLayer(6 , 2)
would make this output:

++++++,/'-=\/=-'\,++++++++++||++++++,/'-=\/=-'\,++++++++++|

because the sixth line in this tile

| |
|++++++++++=""=++++++++++++++|
|++++++++/ _ _ \++++++++++++|
|+++++++| d b |+++++++++++|
|+++++++\ /\ /+++++++++++|
|++++++,/'-=\/=-'\,++++++++++|
|+++++/ / \ \+++++++++|
|++++| / \ |++++++++|
|++++\/ \ / \/++++++++|
|++++++++'. .'++++++++++++|
|jgs+++++_|`~~`|_++++++++++++|
|++++++++/|\ /|\++++++++++++|
| |

looks like this:

|++++++,/'-=\/=-'\,++++++++++|

and that line of the tile has to be repeated 2 times when the width of
the course is 2.

*/

int main (void)
{
int width, courses ;

GetDims (width, courses);

if (width == 0 ||courses == 0)

{
cout << "Dimensions must be positive.\n";
cout << endl;
}
else
{
MakePattern(width, courses);
}

return 0;
}

/* function definition */
void GetDims (int& width, int& courses)
{
cout << "How many tiles wide do you want your floor to be?\n";
cin >> width;
cout << "How many courses do you want in your floor?\n";
cin >> courses;
cout << endl;
}

/* function definition */
void MakePattern(int the_width, int the_courses)
{

for (i=0; i<=courses; i++)
{
MakeCourse(a_width)
}
}

/* function definition */
void MakeCourse (int a_width)
{

for (i=0; i<= 13; i++)
{
MakeLayer(layer, a_width);
}
}

/* function definition */
void MakeLayer (int layer, int a_width)
{
for (i=0; i<=a_width; i++)
{
if (layer==1)
{
cout << "| |\n";
}
else if (layer==2)
{
cout << "|++++++++++=""=++++++++++++++|\n";
}
else if (layer==3)
{
cout << "|++++++++/ _ _ \\++++++++++++|\n";
}
else if (layer==4)
{
cout << "|+++++++| d b |+++++++++++|\n";
}
else if (layer==5)
{
cout << "|+++++++\\ /\\ /+++++++++++|\n";
}
else if (layer==6)
{
cout << "|++++++,/'-=\\/=-'\\,++++++++++|\n";
}
else if (layer==7)
{
cout << "|+++++/ / \\ \\+++++++++|\n";
}
else if (layer==8)
{
cout << "|++++| / \\ |++++++++|\n";
}
else if (layer==9)
{
cout << "|++++\\/ \\ / \\/++++++++|\n";
}
else if (layer==10)
{
cout << "|++++++++'. .'++++++++++++|\n";
}
else if (layer==11)
{
cout << "|jgs+++++_|`~~`|_++++++++++++|\n";
}
else if (layer==12)
{
cout << "|++++++++/|\\ /|\\++++++++++++|\n";
}
else if (layer==13)
{
cout << "| |\n";
cout << endl;
}
}

}




sorry about the spacing. Every time I past the code it pushes the text to the left after I hit submit. I spaced it out manually after pasting but it still pushes the text after 'submit' is clicked

Neema
Last edited on
correction

*****

void MakePattern(int the_width, int the_courses)
{

for (i=0; i<=courses; i++)
{
MakeCourse(the_width)
}

*****
You need to put your code within [code] tags. This can also be done using the <> button in the formatting options.
Last edited on
First issue: None of your for loops have actually declared the variable 'i'. You need to put 'int' before 'i'. Eg: for(int i=0; i<10;i++)

Second issue: MakeCourse() has no idea what the variable 'courses' is.

Third: no semi-colon after MakeCourse(the_width)

Fourth: no such variable as 'layer' that's being passed to the MakeCourse function.

You really need to go through your code very slowly and verify that these types of problems do not exist. Your two leading issues are either spelling mistakes or trying to use variables that don't exist, so I would advise you to slow down and put more care into creating your functions. Your for loops are really not the problem here (although they might be as I haven't bothered to get that far).

Fix the rest though, and we'll see.
How would I introduce 'layer' to MakeCourse? I can't take out a variable from MakeLayer and I can't add a variable to the function argument MakeCourse. Do I declare 'layer' as an int before the 'for' statement in the MakeCourse function call?

*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
int main (void)
{
   int width, courses ;

   GetDims (width, courses);
     if (width == 0 ||courses == 0)

   {
       cout << "Dimensions must be positive.\n";
       cout << endl;
   }
   else
   {
       MakePattern(width, courses);
   }


   return 0;
}

/* function definition */
void GetDims (int& width, int& courses)
{
   cout << "How many tiles wide do you want your floor to be?\n";
   cin >> width;
   cout << "How many courses do you want in your floor?\n";
   cin >> courses;
   cout << endl;
}

/* function definition */
void MakePattern(int the_width, int the_courses)
{
  
    for (int i=0; i<=the_courses; i++)
   {
       MakeCourse(the_width);
   }
}

/* function definition */
void MakeCourse (int a_width)
{
   
   for (int i=0; i<= 13; i++)
   {
       MakeLayer(layer, a_width);
   }
}

/* function definition */
void MakeLayer (int layer, int a_width)
 {

     for (int i=0; i<=a_width; i++)

      {
       if (layer==1)
       {
           cout << "|                            |\n";
       }
       else if (layer==2)
       {
           cout << "|++++++++++=""=++++++++++++++|\n";
       }
       else if (layer==3)
       {
           cout << "|++++++++/ _  _ \\++++++++++++|\n";
       }
       else if (layer==4)
       {
           cout << "|+++++++|  d  b  |+++++++++++|\n";
       }
       else if (layer==5)
       {
           cout << "|+++++++\\   /\\   /+++++++++++|\n";
       }
       else if (layer==6)
       {
           cout << "|++++++,/'-=\\/=-'\\,++++++++++|\n";
       }
       else if (layer==7)
       {
           cout << "|+++++/ /        \\ \\+++++++++|\n";
       }
       else if (layer==8)
       {
           cout << "|++++| /          \\ |++++++++|\n";
       }
       else if (layer==9)
       {
           cout << "|++++\\/ \\        / \\/++++++++|\n";
       }
       else if (layer==10)
       {
           cout << "|++++++++'.    .'++++++++++++|\n";
       }
       else if (layer==11)
       {
           cout << "|jgs+++++_|`~~`|_++++++++++++|\n";
       }
       else if (layer==12)
       {
           cout << "|++++++++/|\\  /|\\++++++++++++|\n";
       }
       else if (layer==13)
       {
           cout << "|                            |\n";
           cout << endl;
        }
  }
}



Last edited on
I changed the parameters for MakeLayer, it makes the tiles but doesn't separate them correctly. It'll make the 13 lines, one after the other without spacing the lines into bricks.

If I leave the \n after each line, the right spacing displays but it wont let me make courses with anything but a width of 1


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
int main (void)
{
   int width, courses ;

   GetDims (width, courses);
     if (width <= 0 || courses <= 0)
    {
       cout << "Dimensions must be positive.\n";
       cout << endl;
    }
     else
    {
       MakePattern(width, courses);
    }

    cout << endl;

   return 0;
}

/* function definition */
void GetDims (int& width, int& courses)
{
   cout << "How many tiles wide do you want your floor to be?\n";
   cin >> width;
   cout << "How many courses do you want in your floor?\n";
   cin >> courses;
   cout << endl;
}

/* function definition */
void MakePattern(int the_width, int the_courses)
{

   for (int i=1; i<=the_courses; i++)
   {
       MakeCourse(the_width);
   }
}

/* function definition */
void MakeCourse (int a_width)
{

   for (int i=1; i<= 13; i++)
   {
       MakeLayer(i, a_width);
   }
}

/* function definition */
void MakeLayer (int layer, int a_width)
{

     for (int layer=1; layer<= a_width; layer++)
      {
       if (layer==1)
       {
           cout << "|                            |";
       }
       else if (layer==2)
       {
           cout << "|++++++++++=\"\"=++++++++++++++|";
       }
       else if (layer==3)
       {
           cout << "|++++++++/ _  _ \\++++++++++++|";
       }
       else if (layer==4)
       {
           cout << "|+++++++|  d  b  |+++++++++++|";
       }
       else if (layer==5)
       {
           cout << "|+++++++\\   /\\   /+++++++++++|";
       }
       else if (layer==6)
       {
           cout << "|++++++,/'-=\\/=-'\\,++++++++++|";
       }
       else if (layer==7)
       {
           cout << "|+++++/ /        \\ \\+++++++++|";
       }
       else if (layer==8)
       {
           cout << "|++++| /          \\ |++++++++|";
       }
       else if (layer==9)
       {
           cout << "|++++\\/ \\        / \\/++++++++|";
       }
       else if (layer==10)
       {
           cout << "|++++++++'.    .'++++++++++++|";
       }
       else if (layer==11)
       {
           cout << "|jgs+++++_|`~~`|_++++++++++++|";
       }
       else if (layer==12)
       {
           cout << "|++++++++/|\\  /|\\++++++++++++|";
       }
       else if (layer==13)
       {
           cout << "|                            |";
        }

       }
}
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* function definition */
void MakeLayer (int layer, int a_width)
{

     for (int i=1; i<= a_width; i++)  // * CHANGE HERE
      {
       if (layer==1)
       {
           cout << "|                            |";
       }
       else if (layer==2)
       {
           cout << "|++++++++++=\"\"=++++++++++++++|";
       }
       else if (layer==3)
       {
           cout << "|++++++++/ _  _ \\++++++++++++|";
       }
       else if (layer==4)
       {
           cout << "|+++++++|  d  b  |+++++++++++|";
       }
       else if (layer==5)
       {
           cout << "|+++++++\\   /\\   /+++++++++++|";
       }
       else if (layer==6)
       {
           cout << "|++++++,/'-=\\/=-'\\,++++++++++|";
       }
       else if (layer==7)
       {
           cout << "|+++++/ /        \\ \\+++++++++|";
       }
       else if (layer==8)
       {
           cout << "|++++| /          \\ |++++++++|";
       }
       else if (layer==9)
       {
           cout << "|++++\\/ \\        / \\/++++++++|";
       }
       else if (layer==10)
       {
           cout << "|++++++++'.    .'++++++++++++|";
       }
       else if (layer==11)
       {
           cout << "|jgs+++++_|`~~`|_++++++++++++|";
       }
       else if (layer==12)
       {
           cout << "|++++++++/|\\  /|\\++++++++++++|";
       }
       else if (layer==13)
       {
           cout << "|                            |";
        }

       }
	 cout << '\n' ;   // * CHANGE HERE 
}


An alternate implementation:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

char * tilePattern[13] =
{
	"|                            |",
	"|++++++++++=\"\"=++++++++++++++|",
	"|++++++++/ _  _ \\++++++++++++|",
	"|+++++++|  d  b  |+++++++++++|",
	"|+++++++\\   /\\   /+++++++++++|",
	"|++++++,/'-=\\/=-'\\,++++++++++|",
	"|+++++/ /        \\ \\+++++++++|",
	"|++++| /          \\ |++++++++|",
	"|++++\\/ \\        / \\/++++++++|",
	"|++++++++'.    .'++++++++++++|",
	"|jgs+++++_|`~~`|_++++++++++++|",
	"|++++++++/|\\  /|\\++++++++++++|",
    "|                            |"
};

/* function definition */
void MakeLayer (int layer, int a_width)
{
	for ( unsigned tile = 0;  tile < a_width ; ++tile )
		cout << tilePattern[layer-1] ;  // 0-12 are valid indexes for tilePattern

	cout << '\n' ;
}

Last edited on
Topic archived. No new replies allowed.