Make Shapes With Arrays??

I'm trying to write a program where the user selects one of six shapes to be made with whatever character they desire but I've ran into a bit of the problem with the code.
I've successfully made all of the shapes with arrays and loops but I cannot figure out how to display them correctly...
Help me please?
Thanks in advance.


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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
  //
//
#include "stdafx.h"
#include <iostream>

using namespace std;



//Prototypes
void Menu();
int GetUserChoice();
void GetUserChar(char userchar);
void ClearGrid(char shape[15][15]);
void FillBorder(char shape[15][15],char userchar);
void FillPlus(char shape[15][15], char userchar);
void FillX(char shape[15][15],char userchar);
void FillCheckerBoard(char shape[15][15], char userchar);
void WriteGrid(char shape[15][15]); //arr
void Output();




///////////////////////////////////////////////////////////////////////////////////////////////////

int _tmain(int argc, _TCHAR* argv[])
{
	char userchar;
	char shape[15][15];
	ClearGrid(shape[15][15]);
	Menu();
	GetUserChoice();
	GetUserChar();
	WriteGrid(GetUserChoice(), &userchar);

	return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void Menu()
{
	cout << "Please select the number of the shape you would like me to create for you.\n";
	cout << "--------------------------------------------------------------------------\n";
	cout << "1. Box\n"
		"2. X\n"
		"3. Plus\n"
		"4. Bordered X\n"
		"5. Bordered Plus\n"
		"6. Checkerboard\n";
	
}
///////////////////////////////////////////////////////////////////////////////////////////////////
int GetUserChoice()
{
	int choice;
	cin >> choice;

	while(choice < 0 || choice > 6)
		cout << "I'm sorry." << choice << "is not a valid option\nPlease try again.";
	
	
	return choice;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
char GetUserChar(char &userchar)
{
	

	cout << "Enter the character you wish to create your shape of choice with!\n";
	cin >> userchar;
	return userchar;

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ClearGrid(char shape[15][15])
{

	//Make every coordinate in array contain a space
	for(int x = 0; x < 15; x++)
		for (int y = 0; y < 15; y++)
			shape[x][y] = ' ';

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void FillBorder(char shape[15][15], char &userchar) //array and char user picked
{
	
	

	//fill top row and bottom row
	for(int x = 0; x < 15; x = x + 14)
		for(int y = 0; y < 15; y++)
			  shape[x][y] = userchar;  //char that user picked

	//fill left column and right column (Except the corners)
	for(int x = 1; x < 15 - 1; x++)
		for(int y = 0; y < 15; y = y + 14)
			shape[x][y] = userchar; // char user picks

	Output();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void FillPlus(char shape[15][15], char &userchar)  //array and char user picked
{
	


	//fills middle row (row 7)
	for(int y = 0; y < 15; y++)
		shape[7][y] = userchar; // char user picked

	//fills middle column (col 7)
	for (int x = 0; x < 15; x++)
		shape[x][7] = userchar; // char user picked
	Output();

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void FillX(char shape[15][15],char &userchar)
{
	
	
	int z = 0;
	for(int i = 0; i<15; i++){
		shape[i][z] = userchar;
		z++;
	}

	int y = 0;
	for(int i = 14; i>-1; i--){
		shape[i][y] = userchar;
		y++;
	}
	Output();
		


}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void FillCheckerBoard(char shape[15][15],char &userchar)
{
	


	//Every other column with even rows
	for(int x = 0; x < 15; x = x + 2)
		for(int y = 0; y < 15; y = y + 2)
			shape[x][y] = userchar; //char user picked

	//Every other column with odd rows
	for(int x = 1; x < 15; x = x + 2)
		for(int y = 1; y <15; y = y + 2)
			shape[x][y] = userchar; //char user picked
	Output();

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void WriteGrid(char shape[15][15])
{
	
	
		switch(GetUserChoice())
	{ 
	
	//In the case user selects box
	case 1:    
		FillBorder(userchar);
		for(int i = 0; i<15; i++){
			cout<<endl;
			for(int j = 0; j<15; j++){
				cout<<shape[j][i];
		}
	}
		
		break;
	//In the case user selects X
	case 2:
		FillX(userchar);

		break;
	//In the case user selects plus
	case 3:
		FillPlus(userchar);
		
		break;
	//In the case user selects bordered x
	case 4:
		FillBorder(userchar);
		FillX(userchar);
		
		break;
	//In the case user selects bordered plus
	case 5:
		FillBorder(userchar);
		FillPlus(userchar);
		
		break;
	//In the case user selects checkerboard
	case 6:
		FillCheckerBoard(userchar);
		
		break;
	}

}

void Output() {
	for(int i = 0; i<15; i++){
		cout<<endl;
		for(int j = 0; j<15; j++){
			cout<<shape[j][i];
		}
	}
}
Last edited on
I'm not a fan of just giving answers to problems, so I won't give you code but you need to look at two things:

1) You are attempting to use both userchar and shape when you only have passed one of the two variables in certain functions.

2) You aren't passing both characters in your functions to produce the shape, but you call for your function to have both, so when you only pass one of the two arguments, your program looks for a function that only takes one argument.
Last edited on
Topic archived. No new replies allowed.