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?
/* 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:
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;
}
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. :)
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.
/* 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:
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
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).
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?
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